private float GetStoppedVelocityX(MovementAcceleration movement) { smoothDampAccelerateVelocity = 0f; float currentVelocityX = velocity; float velocityX = Mathf.Sign(currentVelocityX) * Mathf.SmoothDamp(Mathf.Abs(currentVelocityX), 0f, ref smoothDampDecelerateVelocity, movement.timeToStop); return(velocityX); }
private float GetVelocity(float moveInput, MovementAcceleration movement) { if (moveInput != 0) { return(GetMovingVelocityX(moveInput, movement)); } else { return(GetStoppedVelocityX(movement)); } }
private float GetMovingVelocityX(float moveInput, MovementAcceleration movement) { smoothDampDecelerateVelocity = 0f; float velocityX; if (movement.instantDirectionChange) { velocityX = Mathf.SmoothDamp(Mathf.Abs(velocity), Mathf.Abs(moveInput) * WorldVelocity, ref smoothDampAccelerateVelocity, movement.timeToFullSpeed); velocityX *= Mathf.Sign(moveInput); } else { float targetVelocity = moveInput * WorldVelocity; velocityX = Mathf.SmoothDamp(velocity, targetVelocity, ref smoothDampAccelerateVelocity, movement.timeToFullSpeed); } return(velocityX); }
private void ReadStats(ScriptableUnit data) { tileVelocity = data.TileVelocity; groundedMovement = data.GroundedMovement; aerialMovement = data.AerialMovement; }