Sign in to follow this  
Ylisaren

Constant speed rotation

Recommended Posts

Hi, I'm creating turrets which should track the player and try to fire at him. That part I have worked out and it works mighty well, the problem is that the turret tracks the player perfectly, while I'd like the turret to use a tracking speed, allowing the player to easier dodge and out manuever the turret. I use Ogre and their quaternions which implements the common interpolation methods for quaternions. The problem is that all of them seems to use a factor in the 0..1 range for interpolation, this seems to make it impossible for me to rotate to the target rotation with a constant rotation speed. I create the quaternions from 2 vectors specifying the current rotation, so I'm guessing another solution which perhaps would be easier and more efficient is to interpolate the 2 vectors instead. Sadly my math isn't quite up for the task so any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
look up spherical linear interpolation (SLERP) of quaternions. They were created exactly to solve this problem.

The issue is that you can think of quaternions as points on the surface of a 4-dimensional sphere, and doing linear interpolation is like taking a "slice" or a chord from this hypersphere, when what you need if you want the rotation to be constant velocity is for the points to travel along the surface of the sphere. That's what SLERP does.

Then, if you decide you want the turrent to track the player with a speed of X, you have to come up with a way specific to your game to translate X into units of frames per second. X, for example, might be specified in revolutions per minute, which you can translate into frames per second.

This way, if you update the turrent every N frames in your game loop, then it can calculate a ratio of what percentage of a full revolution this should perform in radians per frame. When you calculate the SLERP, use this percentage to scale the time value accordingly.

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