Measure difference in rotation from direction of velocity
ProjectorX
Member Posts: 45
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?
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