Compare commits
2 Commits
3d964a33e1
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 32fe394b58 | |||
| bbf726c560 |
@@ -911,7 +911,7 @@ Rigidbody:
|
||||
m_Bits: 0
|
||||
m_ImplicitCom: 1
|
||||
m_ImplicitTensor: 1
|
||||
m_UseGravity: 0
|
||||
m_UseGravity: 1
|
||||
m_IsKinematic: 0
|
||||
m_Interpolate: 0
|
||||
m_Constraints: 112
|
||||
|
||||
@@ -7,6 +7,8 @@ public class PlayerMove : MonoBehaviour
|
||||
[SerializeField] private Rigidbody rb;
|
||||
[SerializeField] private Vector3 StartPos;
|
||||
|
||||
bool vertical;
|
||||
bool horizontal;
|
||||
private void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
@@ -16,9 +18,31 @@ public class PlayerMove : MonoBehaviour
|
||||
{
|
||||
float horizontalInput = Input.GetAxis("Horizontal");
|
||||
float verticalInput = Input.GetAxis("Vertical");
|
||||
|
||||
Vector3 moveDirection = new Vector3(horizontalInput,0, verticalInput);
|
||||
moveDirection.Normalize();
|
||||
horizontalInput = Mathf.Round(horizontalInput);
|
||||
verticalInput = Mathf.Round(verticalInput);
|
||||
|
||||
Vector3 moveDirection;
|
||||
|
||||
if (horizontalInput != 0 && horizontal == true)
|
||||
{
|
||||
vertical = false;
|
||||
moveDirection = new Vector3(horizontalInput,0, 0);
|
||||
moveDirection.Normalize();
|
||||
|
||||
}
|
||||
else if (verticalInput != 0 && vertical == true)
|
||||
{
|
||||
horizontal = false;
|
||||
moveDirection = new Vector3(0, 0, verticalInput);
|
||||
moveDirection.Normalize();
|
||||
}
|
||||
else
|
||||
{
|
||||
moveDirection = new Vector3(0, 0, 0);
|
||||
horizontal = true;
|
||||
vertical = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
transform.Translate(moveDirection * speed * Time.deltaTime, Space.World);
|
||||
|
||||
Reference in New Issue
Block a user