I dont know how make diagonal movement im very new in this and a frind give me this code i have an idea of how it works but im not completley sure can someone help me to make a diagonal movement?
public class Player : MonoBehaviour {
private Rigidbody rb;
private Vector3 verticalVelocity;
public float speed;
private Vector3 velocity;
void Start() {
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (Input.GetAxis("Vertical") != 0) MovementVertical();
if (Input.GetAxis("Horizontal") != 0) MovementHorizontal();
}
public void MovementVertical()
{
verticalVelocity = this.transform.forward * speed * Input.GetAxis("Vertical");
verticalVelocity.y = rb.velocity.y;
rb.velocity = verticalVelocity;
}
public void MovementHorizontal()
{
verticalVelocity = this.transform.right * speed * Input.GetAxis("Horizontal");
verticalVelocity.y = rb.velocity.y;
rb.velocity = verticalVelocity;
}
}
by the way thanks for the help