I recently ran into an issue when applying forces to an object. I was working with this question. I am trying to add forces to my character as certain keys are pressed. Here are the keys and their direction of force:
W
= forward
S
= backward
A
= leftward
D
= rightward
As I hit any of the keys, a force is added to its direction. However, a problem arises with diagonal movements as a different technique would be needed to define direction. I am having trouble with defining diagonal directions. For instance, (10, 10, 0)
would add the force 10 on x
and y
. This will not work. I need to add 10 to a new direction; this direction will be the diagonal consisting of the two directions combined. I will add the force to this direction. I am puzzled on how I would define such a direction with the (x, y, z)
format. How could I define a diagonal direction?