B
Benjamin Herne
Guest
I have a character, and the keys are thus: W, forward, S, back, A, left and D, right. This is based on the object's direction, and data for it's speed in contained in the variables fb_vel (w/s) amd rl_vel (a/d). They are then translated into x velocity and y velocity with the following code:
My problem is, that when I press A or D, it doesn't move left or right, it moves on a diagonal.
Code:
if direction >= 0 && direction < 90 {
x_vel = fb_vel * cos(direction);
y_vel = fb_vel * sin(direction);
}
if directionrl >= 270 && directionrl < 360 {
x_vel += rl_vel * cos(360 - directionrl);
y_vel += rl_vel * sin(360 - directionrl) * -1;
}