I have a simple WASD controller to rotate the player, but if I press W and the player has been rotated by 20 degrees, it will only rotate around the x axis.

Yes, it's logical, but how I should I calculate rotation around the x and y axis?

I want to rotate around the x and y axis at the same time.

  • \$\begingroup\$ Please note the changes I have made. rotation is different to translation, and it was clear that you were asking about rotation, but appeared to be using translation-based terms. That said, I am still somewhat confused by your question; The problem you describe does not make sense (if you rotate around any axis by 20 degrees, you can change the local axis, and thus alter the way further rotation applies; it should not prevent such rotation, outright), and to be perfectly honest, the parts of this question I do understand have already been covered multiple times on this very site. \$\endgroup\$ – Gnemlock Feb 19 '17 at 3:51
  • \$\begingroup\$ What have you tried, so far? And when you say "rotate 20 degrees", what axis are you rotating around? Is there any visual representation you can give of what you have, at the moment? \$\endgroup\$ – Gnemlock Feb 19 '17 at 3:51
  • \$\begingroup\$ This question is poorly phrased, contains insufficient information, and is three months old. Why was it bumped? \$\endgroup\$ – 3Dave Jun 2 '17 at 22:40

You just have to use the trigonometric ratios. Lets say that you have rotated the character 20 degrees and you have a speed of 2 pixels per update.

PosX += cos(20)*2
PosY += sin(20)*2

In this example the x would increase with 1.88 pixels and the y would increase with 0.68 pixels per update. enter image description here

  • \$\begingroup\$ The question is about rotation, not translation. \$\endgroup\$ – 3Dave Jun 2 '17 at 22:40
  • \$\begingroup\$ Try and read the post before the edit. He wanted to know how much x AND y would increase if it was rotated. \$\endgroup\$ – Klemmensen Jun 6 '17 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.