Hello guys, I’m with one doubt, related to the diagonal movement, I’ve searched for questions like this, but the diagonal script movement is already made, so as a beginner I have a doubt about how can i do the diagonal movement, I’m using a script like this to make the movement of anything:
void Update() {
if(Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) {
transform.Translate(Vector3.forward*SpeedZ);
}
else if(Input.GetKey(KeyCode.S)||Input.GetKey(KeyCode.DownArrow)) {
transform.Translate(Vector3.back*SpeedZ);
}
else if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) {
transform.Translate(Vector3.left*SpeedX);
}
else if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) {
transform.Translate(Vector3.right*SpeedX);
}
}
So the diagonal movement is described by the drawing that I’ve made
[17209-diagonal+movement.png|17209]
The Cartesian plane that I’ve made, representing the vectors of the movement, and the vectors of the diagonal movement, so my question is, how can I do it? I’ve thought in divide by e.g the vectors W by D to achieve the diagonal movement forward right, something like that:
Vector2 diagonal = W_Movement/D_Movement;
The W_Movement is a Vector, so I don’t know if this is right, I want to understand how it works in the Cartesian plane, and if my propose it’s right!