Move the movement code to a seperate function
This commit is contained in:
parent
cfa7b830d7
commit
d216580bca
1 changed files with 14 additions and 7 deletions
|
@ -11,6 +11,16 @@ public class Player : MonoBehaviour
|
||||||
private bool isWalking;
|
private bool isWalking;
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
|
{
|
||||||
|
HandleMovement();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsWalking()
|
||||||
|
{
|
||||||
|
return isWalking;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleMovement()
|
||||||
{
|
{
|
||||||
Vector2 inputVector = gameInput.GetMovementVectorNormalized();
|
Vector2 inputVector = gameInput.GetMovementVectorNormalized();
|
||||||
|
|
||||||
|
@ -32,7 +42,8 @@ public class Player : MonoBehaviour
|
||||||
if (canMove)
|
if (canMove)
|
||||||
{
|
{
|
||||||
moveDir = moveDirX;
|
moveDir = moveDirX;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// Cannot move on X so attempt to move on Z
|
// Cannot move on X so attempt to move on Z
|
||||||
Vector3 moveDirZ = new Vector3(0, 0, moveDir.z).normalized;
|
Vector3 moveDirZ = new Vector3(0, 0, moveDir.z).normalized;
|
||||||
|
@ -40,7 +51,8 @@ public class Player : MonoBehaviour
|
||||||
if (canMove)
|
if (canMove)
|
||||||
{
|
{
|
||||||
moveDir = moveDirZ;
|
moveDir = moveDirZ;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// Cannot move at all
|
// Cannot move at all
|
||||||
}
|
}
|
||||||
|
@ -57,9 +69,4 @@ public class Player : MonoBehaviour
|
||||||
transform.forward = Vector3.Slerp(transform.forward, moveDir, Time.deltaTime * rotateSpeed);
|
transform.forward = Vector3.Slerp(transform.forward, moveDir, Time.deltaTime * rotateSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsWalking()
|
|
||||||
{
|
|
||||||
return isWalking;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue