[gameprogrammer] Re: Racing Game

  • From: "Hermann K. Peterscheck" <hermann@xxxxxxxxxxxx>
  • To: <gameprogrammer@xxxxxxxxxxxxx>
  • Date: Sat, 23 Dec 2006 14:00:43 -0700

Depending on how complicated you want to get you could make a generic
class that contains position (x,y,z), checked/unchecked state Boolean,
and order such that you always know where the next unchecked point is.
It would then be fairly simple to make a vector of checkpoints and do a
lookup to see which one the next is (if you wanted to optimize a bit you
could then store which one is next and then only do the update when the
state of one of the current one changes). Then you could easily do
things like distance checks, heading vectors (for wrong way arrow, or
perhaps an arrow pointing where the checkpoint is). 

 

Telling if someone is going the "wrong" way can be a bit tricky
depending on the track layout. For example in simple cases you just do a
dot product for the normalized heading vector of the vehicle and the
vector from the next check point to the vehicle. This won't work in
cases such as "S" curves as you may very well be heading away from the
next checkpoint and yet you are still going in the "right" direction.
This could be solved by adding more check points of course, but perhaps
something more clever like only checking wrong way if someone is off the
track for a while, has a low velocity, or if they are heading away from
the checkpoint for a certain period of time. You could also do something
more solid like make a simple vector field that dictates which direction
on the track the car should be going and then do a vector comparison
between the car's heading and the road's heading. All that work just for
an arrow :-)

 

Sounds like you're about 90% of the way there with the checkpoints
though, which is really the critical part.

 

Hermann

 

________________________________

From: gameprogrammer-bounce@xxxxxxxxxxxxx
[mailto:gameprogrammer-bounce@xxxxxxxxxxxxx] On Behalf Of Edilson
Vasconcelos de Melo Junior
Sent: Saturday, December 23, 2006 2:04 PM
To: gameprogrammer@xxxxxxxxxxxxx
Subject: [gameprogrammer] Racing Game

 

Hi,

 

I working on a racing game and I have a problem: To know whether the
player finished the race I test if the car position is in the finish
line, but the problem is if the player starts running, turns the car and
then drives in the wrong way it will end up winning the race :-(. How
could I know the player is in the wrong way? I put several check points
and uncheck them if it was already checked, but I really would like to
put a sign in the screen telling him his is in the wrong way.

 

Thanks a lot and Marry Xmas!!!

Dirso.

 

Other related posts: