Animace 2+
This commit is contained in:
@@ -734,6 +734,9 @@ MonoBehaviour:
|
|||||||
gravity: -20
|
gravity: -20
|
||||||
groundedGravity: -5
|
groundedGravity: -5
|
||||||
cameraTransform: {fileID: 6707832248248563092}
|
cameraTransform: {fileID: 6707832248248563092}
|
||||||
|
animator: {fileID: 9099213046038254594}
|
||||||
|
animationDamping: 0.075
|
||||||
|
crouchKey: 306
|
||||||
--- !u!114 &710593002191720509
|
--- !u!114 &710593002191720509
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -939,7 +942,7 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier: Assembly-CSharp::MegaKoop.Game.Networking.SteamLocalInputSender
|
m_EditorClassIdentifier: Assembly-CSharp::MegaKoop.Game.Networking.SteamLocalInputSender
|
||||||
characterNetwork: {fileID: 8235037133905039757}
|
characterNetwork: {fileID: 8235037133905039757}
|
||||||
sendInterval: 0.05
|
sendInterval: 0.05
|
||||||
cameraTransform: {fileID: 0}
|
cameraTransform: {fileID: 6707832248248563092}
|
||||||
--- !u!114 &3442404066554451922
|
--- !u!114 &3442404066554451922
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -1947,8 +1947,12 @@ MonoBehaviour:
|
|||||||
rotationSharpness: 15
|
rotationSharpness: 15
|
||||||
airControlResponsiveness: 60
|
airControlResponsiveness: 60
|
||||||
jumpHeight: 1.6
|
jumpHeight: 1.6
|
||||||
gravity: -1
|
gravity: -10
|
||||||
groundedGravity: -0.01
|
groundedGravity: -0.01
|
||||||
|
jumpBufferTime: 0.1
|
||||||
|
coyoteTime: 0.1
|
||||||
|
upwardGravityMultiplier: 1
|
||||||
|
fallGravityMultiplier: 10
|
||||||
cameraTransform: {fileID: 266386425542752718}
|
cameraTransform: {fileID: 266386425542752718}
|
||||||
animator: {fileID: 3962868364137827229}
|
animator: {fileID: 3962868364137827229}
|
||||||
animationDamping: 0.075
|
animationDamping: 0.075
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ namespace MegaKoop.Game
|
|||||||
[SerializeField] private float jumpHeight = 1.6f;
|
[SerializeField] private float jumpHeight = 1.6f;
|
||||||
[SerializeField] private float gravity = -20f;
|
[SerializeField] private float gravity = -20f;
|
||||||
[SerializeField] private float groundedGravity = -5f;
|
[SerializeField] private float groundedGravity = -5f;
|
||||||
|
[SerializeField, Range(0f, 0.3f)] private float jumpBufferTime = 0.1f;
|
||||||
|
[SerializeField, Range(0f, 0.3f)] private float coyoteTime = 0.1f;
|
||||||
|
[SerializeField, Min(0.5f)] private float upwardGravityMultiplier = 1f;
|
||||||
|
[SerializeField, Min(1f)] private float fallGravityMultiplier = 2.5f;
|
||||||
|
|
||||||
[Header("Camera Reference")]
|
[Header("Camera Reference")]
|
||||||
[SerializeField] private Transform cameraTransform;
|
[SerializeField] private Transform cameraTransform;
|
||||||
@@ -33,6 +37,8 @@ namespace MegaKoop.Game
|
|||||||
private bool lastGrounded;
|
private bool lastGrounded;
|
||||||
private bool isDead;
|
private bool isDead;
|
||||||
private MegaKoop.Game.Networking.ICharacterInputSource inputSource;
|
private MegaKoop.Game.Networking.ICharacterInputSource inputSource;
|
||||||
|
private float lastJumpPressedTime = float.NegativeInfinity;
|
||||||
|
private float lastTimeGrounded = float.NegativeInfinity;
|
||||||
|
|
||||||
// Animator parameter hashes
|
// Animator parameter hashes
|
||||||
private int hashMoveX;
|
private int hashMoveX;
|
||||||
@@ -86,6 +92,8 @@ namespace MegaKoop.Game
|
|||||||
InitializeAnimatorHashes();
|
InitializeAnimatorHashes();
|
||||||
|
|
||||||
Vector2 moveInput = ReadMovementInput();
|
Vector2 moveInput = ReadMovementInput();
|
||||||
|
TrackJumpInput();
|
||||||
|
|
||||||
Vector3 desiredMove = CalculateDesiredMove(moveInput);
|
Vector3 desiredMove = CalculateDesiredMove(moveInput);
|
||||||
bool hasMoveInput = desiredMove.sqrMagnitude > 0f;
|
bool hasMoveInput = desiredMove.sqrMagnitude > 0f;
|
||||||
|
|
||||||
@@ -192,39 +200,63 @@ namespace MegaKoop.Game
|
|||||||
|
|
||||||
private void UpdateGroundedStateBeforeGravity()
|
private void UpdateGroundedStateBeforeGravity()
|
||||||
{
|
{
|
||||||
if (isGrounded && verticalVelocity < 0f)
|
if (isGrounded)
|
||||||
{
|
{
|
||||||
verticalVelocity = groundedGravity;
|
lastTimeGrounded = Time.time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleJumpInput()
|
private void HandleJumpInput()
|
||||||
{
|
{
|
||||||
if (!isGrounded)
|
bool bufferedJump = Time.time - lastJumpPressedTime <= jumpBufferTime;
|
||||||
|
bool coyoteAvailable = Time.time - lastTimeGrounded <= coyoteTime;
|
||||||
|
|
||||||
|
if (!bufferedJump)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ShouldJumpThisFrame())
|
if (isGrounded || coyoteAvailable)
|
||||||
{
|
{
|
||||||
verticalVelocity = Mathf.Sqrt(jumpHeight * -2f * gravity);
|
verticalVelocity = Mathf.Sqrt(jumpHeight * -2f * gravity);
|
||||||
isGrounded = false;
|
isGrounded = false;
|
||||||
|
lastJumpPressedTime = float.NegativeInfinity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ShouldJumpThisFrame()
|
private void TrackJumpInput()
|
||||||
{
|
{
|
||||||
|
bool jumpPressed = false;
|
||||||
|
|
||||||
if (inputSource != null)
|
if (inputSource != null)
|
||||||
{
|
{
|
||||||
return inputSource.JumpPressed;
|
jumpPressed = inputSource.JumpPressed;
|
||||||
|
}
|
||||||
|
else if (Input.GetButtonDown("Jump"))
|
||||||
|
{
|
||||||
|
jumpPressed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Input.GetButtonDown("Jump");
|
if (jumpPressed)
|
||||||
|
{
|
||||||
|
lastJumpPressedTime = Time.time;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyGravity()
|
private void ApplyGravity()
|
||||||
{
|
{
|
||||||
verticalVelocity += gravity * Time.deltaTime;
|
float gravityMultiplier = verticalVelocity > 0f ? upwardGravityMultiplier : fallGravityMultiplier;
|
||||||
|
float currentGravity = gravity * gravityMultiplier;
|
||||||
|
|
||||||
|
if (isGrounded && verticalVelocity < 0f)
|
||||||
|
{
|
||||||
|
verticalVelocity = groundedGravity;
|
||||||
|
lastTimeGrounded = Time.time;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
verticalVelocity += currentGravity * Time.deltaTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateAnimator()
|
private void UpdateAnimator()
|
||||||
@@ -283,6 +315,10 @@ namespace MegaKoop.Game
|
|||||||
gravity = Mathf.Min(-0.01f, gravity);
|
gravity = Mathf.Min(-0.01f, gravity);
|
||||||
groundedGravity = Mathf.Clamp(groundedGravity, gravity, 0f);
|
groundedGravity = Mathf.Clamp(groundedGravity, gravity, 0f);
|
||||||
animationDamping = Mathf.Max(0f, animationDamping);
|
animationDamping = Mathf.Max(0f, animationDamping);
|
||||||
|
jumpBufferTime = Mathf.Clamp(jumpBufferTime, 0f, 0.3f);
|
||||||
|
coyoteTime = Mathf.Clamp(coyoteTime, 0f, 0.3f);
|
||||||
|
upwardGravityMultiplier = Mathf.Max(0.5f, upwardGravityMultiplier);
|
||||||
|
fallGravityMultiplier = Mathf.Max(1f, fallGravityMultiplier);
|
||||||
EnsureAnimatorReference();
|
EnsureAnimatorReference();
|
||||||
InitializeAnimatorHashes();
|
InitializeAnimatorHashes();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user