Jump to content
  • Advertisement
Sign in to follow this  
domin

Problem with combined rotations

This topic is 2780 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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.

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
I guess you rotate the player and camera in local-space respectively. but i think you should rotate them in the same world space.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!