Animace 2+
This commit is contained in:
@@ -36,6 +36,7 @@ namespace MegaKoop.Game
|
||||
private bool isGrounded;
|
||||
private bool lastGrounded;
|
||||
private bool isDead;
|
||||
private bool isJumping;
|
||||
private MegaKoop.Game.Networking.ICharacterInputSource inputSource;
|
||||
private float lastJumpPressedTime = float.NegativeInfinity;
|
||||
private float lastTimeGrounded = float.NegativeInfinity;
|
||||
@@ -44,10 +45,11 @@ namespace MegaKoop.Game
|
||||
private int hashMoveX;
|
||||
private int hashMoveZ;
|
||||
private int hashSpeed;
|
||||
private int hashMoveSpeedNormalized;
|
||||
private int hashIsGrounded;
|
||||
private int hashIsCrouching;
|
||||
private int hashIsDead;
|
||||
private int hashJump;
|
||||
private int hashIsJumping;
|
||||
private bool animatorHashesInitialized;
|
||||
|
||||
private void Reset()
|
||||
@@ -220,6 +222,7 @@ namespace MegaKoop.Game
|
||||
{
|
||||
verticalVelocity = Mathf.Sqrt(jumpHeight * -2f * gravity);
|
||||
isGrounded = false;
|
||||
isJumping = true;
|
||||
lastJumpPressedTime = float.NegativeInfinity;
|
||||
}
|
||||
}
|
||||
@@ -252,6 +255,7 @@ namespace MegaKoop.Game
|
||||
{
|
||||
verticalVelocity = groundedGravity;
|
||||
lastTimeGrounded = Time.time;
|
||||
isJumping = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -273,24 +277,21 @@ namespace MegaKoop.Game
|
||||
float denom = Mathf.Max(0.01f, moveSpeed);
|
||||
float moveX = Mathf.Clamp(localVelocity.x / denom, -1f, 1f);
|
||||
float moveZ = Mathf.Clamp(localVelocity.z / denom, -1f, 1f);
|
||||
float normalizedSpeed = Mathf.Clamp01(speed / moveSpeed);
|
||||
|
||||
// Update animator parameters
|
||||
animator.SetFloat(hashSpeed, speed);
|
||||
animator.SetFloat(hashMoveSpeedNormalized, normalizedSpeed);
|
||||
animator.SetFloat(hashMoveX, moveX, animationDamping, Time.deltaTime);
|
||||
animator.SetFloat(hashMoveZ, moveZ, animationDamping, Time.deltaTime);
|
||||
animator.SetBool(hashIsGrounded, isGrounded);
|
||||
animator.SetBool(hashIsJumping, isJumping);
|
||||
|
||||
// Crouch input (currently only supports local input, can be extended via inputSource)
|
||||
bool isCrouching = !isDead && Input.GetKey(crouchKey);
|
||||
animator.SetBool(hashIsCrouching, isCrouching);
|
||||
|
||||
// Jump trigger - when leaving ground with upward velocity
|
||||
if (lastGrounded && !isGrounded && verticalVelocity > 0.1f)
|
||||
{
|
||||
animator.ResetTrigger(hashJump);
|
||||
animator.SetTrigger(hashJump);
|
||||
}
|
||||
|
||||
animator.SetBool(hashIsDead, isDead);
|
||||
lastGrounded = isGrounded;
|
||||
}
|
||||
@@ -345,7 +346,8 @@ namespace MegaKoop.Game
|
||||
hashIsGrounded = Animator.StringToHash("IsGrounded");
|
||||
hashIsCrouching = Animator.StringToHash("IsCrouching");
|
||||
hashIsDead = Animator.StringToHash("IsDead");
|
||||
hashJump = Animator.StringToHash("Jump");
|
||||
hashIsJumping = Animator.StringToHash("IsJumping");
|
||||
hashMoveSpeedNormalized = Animator.StringToHash("MoveSpeedNormalized");
|
||||
animatorHashesInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user