Character rotation smoothing.

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Character rotation smoothing.

Post by 3DModelerMan »

I'm working on making my character rotate when it changes direction. This is my code:

Code: Select all

//Apply rotation
 static irr::core::vector3df rot = getSceneNode()->getRotation();
 
 //Only update when moving.
 if ( m_direction.getLength() != 0 )
 {
  irr::core::vector3df angle = vel.normalize().getHorizontalAngle();
  angle.Y += 180;
  
  //Smooth later
  rot.Y = angle.Y;
 }
	
 getSceneNode()->setRotation(rot);
That snaps it to the direction it's going, but I want it to rotate smoothly the shortest direction. But everything I try produces nasty flickering.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
Mag-got
Posts: 42
Joined: Tue Dec 04, 2007 5:53 pm

Post by Mag-got »

You could interpolate between the curren't angle and the wanted angle.
If you want to do it with vector3d, the class has the function getInterpolated, where d should be (time since rotation start) / (time rotation should take)

The shorter direction thing, the other way is abs(angle-target) and the other way is 360-abs(angle-target)
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

Post by 3DModelerMan »

Thanks, I'll try that.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
Post Reply