It is currently Tue Dec 10, 2013 5:26 pm

 All times are UTC

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: about CheckAngle();Posted: 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: Posted: Mon Jun 07, 2010 11:37 am
 Corpse Bride

Joined: Tue Jul 01, 2008 11:44 pm
Posts: 2221
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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 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 forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ Forums    Forum Rules and Posting Guidelines Wiki Discussion    Help    Content Issues Game Programming Discussion    C and C++ Game Programming    Java Game Programming    Language Agnostic Programming    .NET Game Programming    VB Game Programming    Mobile Game Programming    Web-Based Game Programming    Other Languages    OpenGL Development    Direct X Development Game Development Discussion    Game Design    Game Media Off-Topic Discussion    Announcements    Off-Topic    Community Projects    News