Problem with combined rotations

Started by
3 comments, last by Yang G 13 years ago
Hi all - I have simple problem with combined rotations. The situation looks like this:

Lets assume that everything is done in 2d.

The camera is right above the player and is looking down at him.
Now, I want to rotate the player according to the mouse cursor, so he is alway looking 'at the mouse cursor'. This is simple - good, old atan2 (player is always in the center of the screen):


float f1 = Input.mousePosition.x - Screen.width / 2.0f;
float f2 = Input.mousePosition.y - Screen.height / 2.0f;

float angle = Mathf.Atan2(f1, f2);


So, rotation of the player is: (0.0f, angle, 0.0f) and its works fine.


But now I want to add camera rotation based on the same rules, so rotation for the camera should be: (Mathf.PI / 2.0f, angle, 0.0f) and here the problem appears... It looks like the camera is rotating faster that the player, or the player is slower that the camera... I suppose that is an illussion from combining two rotations together (for the camera and the player), but I can't find a solution to solve this problem.


Please, help :)
Advertisement
What rotation is (a,b,c)? The one along the (a,b,c) axis with an angle proportional the the length of the vector? Or are you using Euler angles? In either case, rotation composition is hard to do with those representations. Use matrices or quaternions instead.
I'm using quaternions internally, but the rotations are exposed as radians to simplify vizualization of the problem: (X axis, Y axis, Z axis). No mater what method is used the combined rotation of the camera and the player still causes this problem.

Maybe I'm not completely clear in the first post - the rotation of the player and the camera are not multiplied together - they are completely independent - just simple Y axis rotations...

I'm afraid I don't understand your problem.
I guess you rotate the player and camera in local-space respectively. but i think you should rotate them in the same world space.

This topic is closed to new replies.

Advertisement