refactor (slowndow): create a function in movement script to apply the slowdown 'keep the logic'
This commit is contained in:
@@ -14,12 +14,17 @@ public class PlayerMovement : MonoBehaviour
|
||||
|
||||
private Vector3 moveDirection;
|
||||
|
||||
// used for root enemies
|
||||
private float baseWalkSpeed;
|
||||
private float slowMultiplier = 1f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_rigidbody = GetComponent<Rigidbody>();
|
||||
input = GetComponent<PlayerInputController>();
|
||||
animator = GetComponent<Animator>();
|
||||
headController = GetComponent<PlayerHeadController>();
|
||||
baseWalkSpeed = WalkSpeed;
|
||||
|
||||
if (m_rigidbody != null)
|
||||
{
|
||||
@@ -27,6 +32,11 @@ public class PlayerMovement : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplySlow(float multiplier)
|
||||
{
|
||||
slowMultiplier = multiplier;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
Vector2 m_moveAmt = input.MoveAmount;
|
||||
@@ -48,7 +58,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
if (headController.isHoldingHead)
|
||||
{
|
||||
m_rigidbody.MovePosition(
|
||||
m_rigidbody.position + Time.deltaTime * WalkSpeed * moveDirection
|
||||
m_rigidbody.position + Time.deltaTime * baseWalkSpeed * slowMultiplier * moveDirection
|
||||
);
|
||||
}
|
||||
else
|
||||
@@ -56,7 +66,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
if (moveDirection.magnitude >= 0.1f)
|
||||
{
|
||||
m_rigidbody.MovePosition(
|
||||
m_rigidbody.position + Time.deltaTime * WalkSpeed * moveDirection
|
||||
m_rigidbody.position + Time.deltaTime * baseWalkSpeed * slowMultiplier * moveDirection
|
||||
);
|
||||
|
||||
Quaternion targetRotation = Quaternion.LookRotation(moveDirection);
|
||||
|
||||
Reference in New Issue
Block a user