Sign in to follow this  

Problem with combined rotations

Recommended Posts

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 :)

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
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...

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this