Jump to content
  • Advertisement
Sign in to follow this  
RavNaz

top-down movement - smooth rotate to face direction

This topic is 3679 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

ok, so currenlty I have an object moving around responding to controller inputs, so that it snaps to the direction you push on the controller, example: // where rasy/rasx are the directions on the pad rotate = atan2f( -rasy, -rasx ); Model.SetRotation(rotate); This works fine, but I want the model to rotate to the new direction, in the shortest arc, and not snap. I've tried various methods that nearly work, but there always seem to be cases where the rotation comes back like 4.71 radians and ends up taking the longest rotation to face the direction. Can someone give me some pointers?

Share this post


Link to post
Share on other sites
Advertisement
Assuming your object has a orientation vector v and you want it to move in the new orientation v'. You just determine if v' is left or right from v. Take the dot product of v' and the perpendicular vector to v and see if its positive or negative.

Something like:


float dot = v.y * v'.x - v.x * v'.y;
if( dot < -angle_speed )
rotate the object clock-wise with angle_speed per second
else if( dot > angle_speed )
rotate the object counter-clock-wise with angle_speed per second
else
rotate the object to v' instantly



I think this should do the trick.

Share this post


Link to post
Share on other sites
thats kind of the direction I was going, except how do I update the new orientation from the angle?

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!