GPWiki.org
GPWiki.org
It is currently Sun May 19, 2013 3:58 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: about CheckAngle();
PostPosted: Mon Jun 07, 2010 11:16 am 
reference: http://rookscape.com/vbgaming/tutBS.php

I followed this tutorial to implment the AI car racing game, but I'm in trouble with the direction of the car.

when a car need to adjust its direction, I subtracted the current direction from the target directon, depends on the value of subtraction. I called TurnRight() or TurnLeft() functions to change the current direction in order to let it get close to the target direction. (I will calculate the target direction every tick).

the problem is when the value of the direction (store as the radians way) changed from the value like 7.8 to 7.8-2PI. the car will not turn the right way. it will keep calling TurnRight() and TurnLeft() sequentially..


how to solve this problem ..

looking forward to your help.. and sorry for my poor English.


Top
  
 
 Post subject:
PostPosted: Mon Jun 07, 2010 11:37 am 
Corpse Bride
User avatar

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2216
Location: England
You would decide whether to turn left of right by seeing on which side the target angle is relative to the current angle.

Of course, you have to correct for the fact that angles wrap.

And you should regularly make sure that the angles are snapped into ranged (-PI, PI]

So
Code:
Let DeltaAngle = TargetAngle - CurrentAngle
While Abs(DeltaAngle)>PI : DeltaAngle=DeltaAngle - Sgn(DeltaAngle)*2*PI : Wend

If DeltaAngle>0 then TurnRight()
If DeltaAngle<0 then TurnLeft()


Hope that helps. :)

_________________
I ain't pushing no moon buttons.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group