Measure difference in rotation from direction of velocity

I'm making a bird-eye-view car to drive around in my game. I want to measure the difference in the direction car is heading from the direction it is pointing for drifting and steering purposes.

Right now, I'm measuring the direction it's moving with:
velangle = vectorToAngle( self.Motion.Linear Velocity.X , self.Motion.Linear Velocity.Y );

And I think that's what's causing the problem, because if it's moving in any quadrant other than the first (i.e velocity X or velocity Y is negative), then it returns a negative number. In other words, it doesn't give me full 360 degrees of measurement.

So when my car is moving exactly 90 degrees (upwards, at any speed) everything works right. If it's pointing 90 degrees, then the difference is 0, if it's pointing 270 degrees, the difference is 0, and if it's pointing 180 or 360 (sideways), the difference is 90 (peak). If it's moving 179 degrees, the difference is 89. I'm trying to do it this way so that there's no drag when the car is facing perfectly backwards.

These are the other variables:
halfrotation = mod( self.rotation +90, 180);
anglediff = abs( self.halfrotation - self.velangle );

Any ideas? How else can I measure the direction the car is moving. Is there anything else that can fix it?

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Try making velangle an 'angle' type attribute. It will give you the full 360 degrees.
  • ProjectorXProjectorX Member Posts: 45
    Oh wow. That's an awesome tip. I totally forgot about that so I'll try it as soon as I get the chance. Thanks.
Sign In or Register to comment.