refactor
This commit is contained in:
@@ -5,12 +5,18 @@ namespace RebootKit.FPPKit {
|
||||
public class FPPLocomotion : MonoBehaviour {
|
||||
[SerializeField] CharacterController m_CharacterController;
|
||||
|
||||
public float maxStrafeSpeed = 2.0f;
|
||||
public float maxMovementSpeedBackward = 2.0f;
|
||||
public float maxMovementSpeed = 4.0f;
|
||||
public float maxSprintSpeed = 15.0f;
|
||||
public float jumpHeight = 1.0f;
|
||||
public float gravity = 10f;
|
||||
public float maxFallSpeed = 20f;
|
||||
public float damping = 20.0f;
|
||||
|
||||
[Range(0.0f, 1.0f)]
|
||||
public float airControlRatio = 0.5f;
|
||||
|
||||
float3 m_CurrentVelocity;
|
||||
bool m_IsFalling;
|
||||
|
||||
@@ -20,8 +26,12 @@ namespace RebootKit.FPPKit {
|
||||
float3 m_PendingInputValue;
|
||||
|
||||
public bool IsGrounded => m_CharacterController.isGrounded;
|
||||
public bool IsMovingBackwards { get; private set; }
|
||||
public bool IsSprinting => m_IsSprinting;
|
||||
public bool IsStrafing { get; private set; }
|
||||
|
||||
public float3 Velocity => m_CurrentVelocity;
|
||||
public float3 Velocity => m_CurrentVelocity;
|
||||
public float3 LocalVelocity => m_CharacterController.transform.InverseTransformDirection(m_CurrentVelocity);
|
||||
|
||||
void Update() {
|
||||
ConsumePendingInput();
|
||||
@@ -42,12 +52,13 @@ namespace RebootKit.FPPKit {
|
||||
}
|
||||
|
||||
void ConsumePendingInput() {
|
||||
// if (!IsGrounded) {
|
||||
// m_PendingInputValue = float3.zero;
|
||||
// return;
|
||||
// }
|
||||
if (!IsGrounded) {
|
||||
m_PendingInputValue *= airControlRatio;
|
||||
}
|
||||
|
||||
m_PendingInputValue.y = 0.0f;
|
||||
|
||||
float3 localInputValue = m_CharacterController.transform.InverseTransformDirection(m_PendingInputValue);
|
||||
|
||||
float pendingInputMagnitude = math.length(m_PendingInputValue);
|
||||
float3 direction = float3.zero;
|
||||
@@ -56,7 +67,21 @@ namespace RebootKit.FPPKit {
|
||||
direction = math.normalize(m_PendingInputValue);
|
||||
}
|
||||
|
||||
float movementSpeed = m_IsSprinting ? maxSprintSpeed : maxMovementSpeed;
|
||||
IsStrafing = false;
|
||||
IsMovingBackwards = false;
|
||||
|
||||
float movementSpeed;
|
||||
if (math.dot(localInputValue, Vector3.forward) <= 0.0f) {
|
||||
movementSpeed = maxMovementSpeedBackward;
|
||||
IsMovingBackwards = true;
|
||||
} else if (m_IsSprinting) {
|
||||
movementSpeed = maxSprintSpeed;
|
||||
} else if (math.abs(localInputValue.x) > 0.0f && math.abs(localInputValue.z) < 0.1f) {
|
||||
movementSpeed = maxStrafeSpeed;
|
||||
} else {
|
||||
movementSpeed = maxMovementSpeed;
|
||||
}
|
||||
|
||||
float3 movementVelocity = m_CurrentVelocity;
|
||||
movementVelocity.y = 0.0f;
|
||||
movementVelocity += direction * (movementSpeed * pendingInputMagnitude);
|
||||
|
||||
Reference in New Issue
Block a user