Let's say that I have a vector (x, y) and it is aligned to the beginning by rotation (for example, 30 degrees up).
If I want to transfer this vector by one relative to the direction (so, one block forward with an angle of 30 degrees up), how would I do it?
I am working to bring a simple third-person game together, and I would like to be able to rotate the character and move it forward, regardless of the rotation, and Iām kinda lost on how to do this.
EDIT:
After answering this question, I went further and realized how to get the opposite, left and right movement, so I decided that I would stick to this here for reference, if anyone needs help.
Given the Gunther2 code, To get the reverse movement, simply subtract the offset from the current position:
position -= displacement;
To get left movement, change the offset variables to
displacement.x = (float)Math.Sin(angle + PI/2); displacement.y = (float)Math.Cos(angle + PI/2);
Replace PI / 2 with 90 if Sin / Cos takes degrees instead of radians.
Then subtract the offset:
position -= displacement;
To get the right movement, just follow the same steps, but add a new movement:
position += displacement;