Feedback
This commit is contained in:
parent
f3dc85b777
commit
700f11bc94
@ -24584,7 +24584,7 @@ GameObject:
|
||||
m_Component:
|
||||
- component: {fileID: 2918029099092491010}
|
||||
m_Layer: 0
|
||||
m_Name: Obstacles
|
||||
m_Name: ObstaclesFBX
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
@ -30577,7 +30577,7 @@ GameObject:
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &3211779145275666690
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -39108,7 +39108,7 @@ GameObject:
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &4479256775088773384
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -5023,10 +5023,22 @@ PrefabInstance:
|
||||
propertyPath: m_Materials.Array.data[0]
|
||||
value:
|
||||
objectReference: {fileID: 138099500}
|
||||
- target: {fileID: 3762423576960139226, guid: aef2a50dc2159e44584497dfc2fdaeb2, type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4441166244158635861, guid: aef2a50dc2159e44584497dfc2fdaeb2, type: 3}
|
||||
propertyPath: m_Materials.Array.data[0]
|
||||
value:
|
||||
objectReference: {fileID: 1849443317}
|
||||
- target: {fileID: 4567716116432550438, guid: aef2a50dc2159e44584497dfc2fdaeb2, type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5881339069548083274, guid: aef2a50dc2159e44584497dfc2fdaeb2, type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6503432965990616960, guid: aef2a50dc2159e44584497dfc2fdaeb2, type: 3}
|
||||
propertyPath: m_Materials.Array.data[0]
|
||||
value:
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -9,18 +9,13 @@ public class ChasePlayerController : MonoBehaviour
|
||||
public float laneDistance = 2.5f; // 0=Left,1=Mid,2=Right
|
||||
public float jumpPower = 0.6f;
|
||||
public float jumpDuration = 1.2f;
|
||||
public float laneSwitchSpeed = 10f;
|
||||
public float laneSwitchSpeed = 10f; // used as units per second
|
||||
|
||||
[Header("Animator Driving")]
|
||||
[Tooltip("If true, sets a float parameter (e.g., 'Speed') each frame. If false, crossfades to a run state by name.")]
|
||||
public bool useSpeedBlendTree = true;
|
||||
[Tooltip("Animator float parameter name for the locomotion blend tree.")]
|
||||
public string speedParamName = "Speed";
|
||||
[Tooltip("Value to push while running (match your thresholds: 1=Run, 2=RunFast, 3=Sprint).")]
|
||||
public float runSpeedParamValue = 2f;
|
||||
[Tooltip("Fallback run/locomotion state name if not using a Speed parameter.")]
|
||||
public string runStateName = "Locomotion";
|
||||
[Tooltip("Base layer index for the states above.")]
|
||||
public int baseLayer = 0;
|
||||
|
||||
[Header("Fall / GameOver Logic")]
|
||||
@ -30,33 +25,27 @@ public class ChasePlayerController : MonoBehaviour
|
||||
public float stateWaitTimeout = 3f;
|
||||
public static System.Action<float> OnMoveSpeedChanged;
|
||||
|
||||
// -------------------------------------------------
|
||||
|
||||
int currentLane = 1;
|
||||
Rigidbody rb;
|
||||
Animator animator;
|
||||
bool isGrounded = true;
|
||||
bool isJumping = false;
|
||||
Vector3 targetLanePosition;
|
||||
|
||||
// touch swipe
|
||||
Vector2 startTouchPosition;
|
||||
bool swipeDetected = false;
|
||||
float minSwipeDistance = 50f;
|
||||
|
||||
// fall tracking
|
||||
float lastObstacleHitTime = -999f;
|
||||
bool waitingForGameOver = false;
|
||||
|
||||
// state hashes
|
||||
int runShortHash, fallShortHash, fallingShortHash;
|
||||
[SerializeField] bool validateStatesOnStart = true;
|
||||
[SerializeField] string runTag = "Run";
|
||||
[SerializeField] string fallTag = "Fall";
|
||||
[SerializeField] string fallingTag = "Falling";
|
||||
|
||||
// NEW: remember original forward speed so we can restore after stumble
|
||||
float originalMoveSpeed;
|
||||
bool unableToMove = false;
|
||||
|
||||
ChaseScoreManager scoreManager;
|
||||
|
||||
@ -66,9 +55,6 @@ public class ChasePlayerController : MonoBehaviour
|
||||
animator = GetComponent<Animator>();
|
||||
scoreManager = FindObjectOfType<ChaseScoreManager>();
|
||||
|
||||
targetLanePosition = transform.position;
|
||||
|
||||
// cache hashes
|
||||
runShortHash = Animator.StringToHash(runStateName);
|
||||
fallShortHash = Animator.StringToHash(fallStateName);
|
||||
fallingShortHash = Animator.StringToHash(fallingStateName);
|
||||
@ -76,49 +62,57 @@ public class ChasePlayerController : MonoBehaviour
|
||||
if (validateStatesOnStart)
|
||||
{
|
||||
if (!animator.HasState(baseLayer, runShortHash))
|
||||
Debug.LogError($"[ChasePlayerController] Run state '{runStateName}' not found on layer {baseLayer}");
|
||||
Debug.LogError($"Run state '{runStateName}' not found");
|
||||
if (!animator.HasState(baseLayer, fallShortHash))
|
||||
Debug.LogError($"[ChasePlayerController] Fall state '{fallStateName}' not found on layer {baseLayer}");
|
||||
Debug.LogError($"Fall state '{fallStateName}' not found");
|
||||
if (!animator.HasState(baseLayer, fallingShortHash))
|
||||
Debug.LogError($"[ChasePlayerController] Falling state '{fallingStateName}' not found on layer {baseLayer}");
|
||||
Debug.LogError($"Falling state '{fallingStateName}' not found");
|
||||
}
|
||||
|
||||
originalMoveSpeed = moveSpeed; // NEW
|
||||
ForceRunStart(); // autorunner
|
||||
originalMoveSpeed = moveSpeed;
|
||||
ForceRunStart();
|
||||
}
|
||||
|
||||
public void SetMoveSpeed(float newSpeed)
|
||||
{
|
||||
moveSpeed = newSpeed;
|
||||
OnMoveSpeedChanged?.Invoke(newSpeed);
|
||||
}
|
||||
bool unableToMove = false;
|
||||
|
||||
void Update()
|
||||
{
|
||||
DriveRunAnimation();
|
||||
if(!unableToMove)
|
||||
{
|
||||
|
||||
if (!unableToMove)
|
||||
{
|
||||
HandleInput();
|
||||
HandleSwipe();
|
||||
}
|
||||
UpdateLaneTarget();
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
MoveForward();
|
||||
SmoothLaneSwitch();
|
||||
}
|
||||
|
||||
// ----------------- Input -----------------
|
||||
|
||||
void HandleInput()
|
||||
{
|
||||
if (isJumping) return;
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.LeftArrow) && currentLane > 0) currentLane--;
|
||||
if (Input.GetKeyDown(KeyCode.RightArrow) && currentLane < 2) currentLane++;
|
||||
if (Input.GetKeyDown(KeyCode.Space) && isGrounded) Jump();
|
||||
if (Input.GetKeyDown(KeyCode.LeftArrow) && currentLane > 0)
|
||||
{
|
||||
currentLane--;
|
||||
TweenToLaneX((currentLane - 1) * laneDistance);
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.RightArrow) && currentLane < 2)
|
||||
{
|
||||
currentLane++;
|
||||
TweenToLaneX((currentLane - 1) * laneDistance);
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
|
||||
Jump();
|
||||
}
|
||||
|
||||
void HandleSwipe()
|
||||
@ -132,43 +126,43 @@ public class ChasePlayerController : MonoBehaviour
|
||||
startTouchPosition = touch.position;
|
||||
swipeDetected = true;
|
||||
break;
|
||||
|
||||
case TouchPhase.Ended:
|
||||
if (!swipeDetected) return;
|
||||
Vector2 swipe = touch.position - startTouchPosition;
|
||||
|
||||
if (swipe.magnitude >= minSwipeDistance)
|
||||
if (swipe.magnitude >= minSwipeDistance && !isJumping)
|
||||
{
|
||||
if (isJumping) { swipeDetected = false; return; }
|
||||
|
||||
if (Mathf.Abs(swipe.x) > Mathf.Abs(swipe.y))
|
||||
{
|
||||
if (swipe.x > 0 && currentLane < 2) currentLane++;
|
||||
else if (swipe.x < 0 && currentLane > 0) currentLane--;
|
||||
}
|
||||
else
|
||||
if (swipe.x > 0 && currentLane < 2)
|
||||
{
|
||||
if (swipe.y > 0 && isGrounded) Jump();
|
||||
currentLane++;
|
||||
TweenToLaneX((currentLane - 1) * laneDistance);
|
||||
}
|
||||
else if (swipe.x < 0 && currentLane > 0)
|
||||
{
|
||||
currentLane--;
|
||||
TweenToLaneX((currentLane - 1) * laneDistance);
|
||||
}
|
||||
}
|
||||
else if (swipe.y > 0 && isGrounded)
|
||||
{
|
||||
Jump();
|
||||
}
|
||||
}
|
||||
|
||||
swipeDetected = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------- Movement -----------------
|
||||
|
||||
void UpdateLaneTarget()
|
||||
void TweenToLaneX(float targetX)
|
||||
{
|
||||
if (isJumping) return;
|
||||
float targetX = (currentLane - 1) * laneDistance;
|
||||
targetLanePosition = new Vector3(targetX, rb.position.y, rb.position.z);
|
||||
}
|
||||
float distance = Mathf.Abs(rb.position.x - targetX);
|
||||
float duration = distance / laneSwitchSpeed;
|
||||
|
||||
void SmoothLaneSwitch()
|
||||
{
|
||||
if (isJumping) return;
|
||||
Vector3 newPos = Vector3.Lerp(rb.position, targetLanePosition, laneSwitchSpeed * Time.fixedDeltaTime);
|
||||
rb.MovePosition(newPos);
|
||||
rb.DOMoveX(targetX, duration).SetEase(Ease.OutQuad);
|
||||
}
|
||||
|
||||
void MoveForward()
|
||||
@ -189,7 +183,7 @@ public class ChasePlayerController : MonoBehaviour
|
||||
Vector3 jumpTarget = rb.position + Vector3.back * forwardDisplacement;
|
||||
|
||||
rb.DOJump(jumpTarget, jumpPower, 1, jumpDuration)
|
||||
.SetEase(Ease.Linear).SetDelay(0.2f)
|
||||
.SetEase(Ease.Linear)
|
||||
.OnStart(() =>
|
||||
{
|
||||
SafeSetTrigger("Jump");
|
||||
@ -200,8 +194,7 @@ public class ChasePlayerController : MonoBehaviour
|
||||
rb.useGravity = true;
|
||||
isGrounded = true;
|
||||
isJumping = false;
|
||||
|
||||
SafeSetTrigger("Land"); // if present
|
||||
SafeSetTrigger("Land");
|
||||
SafeSetBool("IsGrounded", true);
|
||||
ForceRunStart();
|
||||
});
|
||||
@ -217,16 +210,10 @@ public class ChasePlayerController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------- Animator driving -----------------
|
||||
|
||||
// CHANGED: can bypass guards when 'ignoreGuards' is true
|
||||
void ForceRunStart(bool ignoreGuards = false)
|
||||
{
|
||||
if (!ignoreGuards)
|
||||
{
|
||||
if (IsInOrGoingTo(fallShortHash) || IsInOrGoingTo(fallingShortHash) || waitingForGameOver)
|
||||
if (!ignoreGuards && (IsInOrGoingTo(fallShortHash) || IsInOrGoingTo(fallingShortHash) || waitingForGameOver))
|
||||
return;
|
||||
}
|
||||
|
||||
if (useSpeedBlendTree && HasParameter(speedParamName, AnimatorControllerParameterType.Float))
|
||||
{
|
||||
@ -245,9 +232,9 @@ public class ChasePlayerController : MonoBehaviour
|
||||
if (useSpeedBlendTree && HasParameter(speedParamName, AnimatorControllerParameterType.Float))
|
||||
{
|
||||
animator.SetFloat(speedParamName, runSpeedParamValue, 0.1f, Time.deltaTime);
|
||||
return;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
var st = animator.GetCurrentAnimatorStateInfo(baseLayer);
|
||||
var nxt = animator.GetNextAnimatorStateInfo(baseLayer);
|
||||
bool inRunNow = st.shortNameHash == runShortHash || st.IsTag(runTag);
|
||||
@ -258,6 +245,7 @@ public class ChasePlayerController : MonoBehaviour
|
||||
animator.CrossFadeInFixedTime(runStateName, 0.1f, baseLayer, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool HasParameter(string name, AnimatorControllerParameterType type)
|
||||
{
|
||||
@ -271,6 +259,7 @@ public class ChasePlayerController : MonoBehaviour
|
||||
if (HasParameter(trig, AnimatorControllerParameterType.Trigger))
|
||||
animator.SetTrigger(trig);
|
||||
}
|
||||
|
||||
void SafeSetBool(string param, bool v)
|
||||
{
|
||||
if (HasParameter(param, AnimatorControllerParameterType.Bool))
|
||||
|
@ -7,8 +7,8 @@ PhysicMaterial:
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: SlipperyFloor
|
||||
dynamicFriction: 0
|
||||
staticFriction: 0
|
||||
dynamicFriction: 0.1
|
||||
staticFriction: 0.1
|
||||
bounciness: 0
|
||||
frictionCombine: 1
|
||||
bounceCombine: 1
|
||||
|
@ -78,31 +78,6 @@ AnimatorState:
|
||||
m_MirrorParameter:
|
||||
m_CycleOffsetParameter:
|
||||
m_TimeParameter:
|
||||
--- !u!1101 &-8535053620550059147
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name:
|
||||
m_Conditions:
|
||||
- m_ConditionMode: 1
|
||||
m_ConditionEvent: Jump
|
||||
m_EventTreshold: 0
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: 6495114904233292258}
|
||||
m_Solo: 0
|
||||
m_Mute: 0
|
||||
m_IsExit: 0
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0.25
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.75
|
||||
m_HasExitTime: 0
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1107 &-8077509795911094576
|
||||
AnimatorStateMachine:
|
||||
serializedVersion: 6
|
||||
@ -351,6 +326,31 @@ AnimatorStateTransition:
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1101 &-5813063112835048604
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name:
|
||||
m_Conditions:
|
||||
- m_ConditionMode: 1
|
||||
m_ConditionEvent: Jump
|
||||
m_EventTreshold: 0
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: 702539109886631529}
|
||||
m_Solo: 0
|
||||
m_Mute: 0
|
||||
m_IsExit: 0
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0.25
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.75
|
||||
m_HasExitTime: 0
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1101 &-5312677403108563446
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
@ -967,7 +967,7 @@ AnimatorStateMachine:
|
||||
m_StateMachine: {fileID: -7106055725313943096}
|
||||
m_Position: {x: 0, y: 0, z: 0}
|
||||
m_AnyStateTransitions:
|
||||
- {fileID: -8535053620550059147}
|
||||
- {fileID: -5813063112835048604}
|
||||
m_EntryTransitions: []
|
||||
m_StateMachineTransitions: {}
|
||||
m_StateMachineBehaviours: []
|
||||
@ -1010,7 +1010,7 @@ AnimatorState:
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Locomotion
|
||||
m_Speed: 200
|
||||
m_Speed: 100
|
||||
m_CycleOffset: 0
|
||||
m_Transitions:
|
||||
- {fileID: 6179490260077758370}
|
||||
@ -1967,10 +1967,10 @@ AnimatorStateMachine:
|
||||
m_ChildStates:
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: 6495114904233292258}
|
||||
m_Position: {x: 200, y: 0, z: 0}
|
||||
m_Position: {x: 360, y: -20, z: 0}
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: 702539109886631529}
|
||||
m_Position: {x: 235, y: 65, z: 0}
|
||||
m_Position: {x: 260, y: 40, z: 0}
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: -2656865062802190136}
|
||||
m_Position: {x: 270, y: 130, z: 0}
|
||||
|
@ -32,10 +32,10 @@ EditorBuildSettings:
|
||||
- enabled: 0
|
||||
path: Assets/Scenes/FeedTheZibu.unity
|
||||
guid: 2ccc400ec771453428e1f25a49906737
|
||||
- enabled: 1
|
||||
- enabled: 0
|
||||
path: Assets/Scenes/ChaseRun.unity
|
||||
guid: be6c423b3d68dcb48bc49a7d2ed4957d
|
||||
- enabled: 0
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/CrateEscape.unity
|
||||
guid: af5c5d2a2d201e24f8c4913ae531addf
|
||||
m_configObjects: {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user