Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / large problem with future game

Author
Message
Doucan
20
Years of Service
User Offline
Joined: 26th Nov 2003
Location: Vermont USA
Posted: 14th Dec 2003 00:04
I'm planning on making a racing game, but I don't know how I'd find out what place each contestant if in. I just can't seem to figure how to check if the player is ahead or behind another player.

I was thinking of asigning each car a variable that increments as it covers more distance. The faster each one goes, the faster the variable increments, the one with the most distance if in 1st place, etc.. As I said, I haven't written this program yet or tested this idea because I want to see how you guys did it.



If you come to a fork in the road, take it!

-Yogi Berra
Neil19533
21
Years of Service
User Offline
Joined: 30th Aug 2003
Location: England
Posted: 14th Dec 2003 02:44
you could do two boxes that is invisable out the sides so if it collides with ine then colides with a second it is increased or decreased some variable if it was to be done with one invisable box out the side then it would constently increase or decrease
some simple code thought up on the spot

and you do the reverse to decreae the position value
its just a quick idea not tested or anything

I wonder where that fish did go, a fish, a fish, a fish, O
Neil19533
21
Years of Service
User Offline
Joined: 30th Aug 2003
Location: England
Posted: 14th Dec 2003 02:50
i didnt explane it well.
if you have a car you would need two boxes sticking out the sides so the object went to the edges of the road one at the front of the car and one at the back if you hit the front one then the back one you must be going behind the car and vice verser so you can youse the knoledge of if you are going backward to decrease your position in the game

I wonder where that fish did go, a fish, a fish, a fish, O
Doucan
20
Years of Service
User Offline
Joined: 26th Nov 2003
Location: Vermont USA
Posted: 15th Dec 2003 00:16
I still don't get it

If you come to a fork in the road, take it!

-Yogi Berra
KNau
22
Years of Service
User Offline
Joined: 25th Nov 2002
Location: Canada
Posted: 15th Dec 2003 01:03
If you are talking about racing in a straight line then your method should work fine. You could have a variable for each car's position on the track and the furthest car vertically is obviously the one out in front.

On a circular track it would be much more difficult because the cars are looping around to the same starting point. The distance relative to the player's car would not give an accurate idea of who is in the lead.

Off the top of my head I would suggest using an invisible dummy "pace car" that is always in the lead of all other cars. No matter what the speed, the car is always positioned a few units ahead of the leader. Measure distances from this pace car to see what order the followers are in.

http://www.canceriannewmedia.com
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 15th Dec 2003 10:51
What you need are waypoints.

If you imagine your racetrack has targets along the road, each numbered incrementally as your heading down the road. Each loop, you have to check the distance between the car, and the waypoint - then there's a couple of rules to impliment.

If the distance to the current waypoint gets below the total track width, then increase the current waypoint number.

If the distance is bigger than the last distance, tell the player there going the wrong way.

If the player dies and you want to restart them on the track - use the previous waypoint.

This system would check for complete laps too, no skipping corners because the waypoint system would know that you missed a waypoint. You could easily check which waypoint each car is heading towards and their respective distances between them, this tells you who is in front.

In terms of implimentation, you need an array of 2D waypoints, going round the track, perhaps you'd only need 6 or 7 over a whole track, but they're best positioned before and after major corners, not too close together though, and not on hairpins because it's easy to cut hairpins. You could make use of shortcuts with sensible waypoint positioning though.

Now for each car, you'd need a waypoint number, and a distance - both stored in an array and updated every loop. Say the whole road is 100 DB units wide, once the distance between the car and the waypoint went below 100, you'd increase the waypoint number, and the next loop the waypoint might be 1000 units away, so each waypoint is linked like a pearl necklace. You could actually lay out waypoints on a much higher resolution and use a very similay system, to make the opponents AI, just have a lot of waypoints with speed settings, then have the AI check the distance and speed of the next waypoint and act accordingly - like how F1 drivers all follow the same route around the track. Actually, you could sorta record the enemy AI on the track, you could race around the track, dropping waypoints along the way, then the AI would try and follow you, you'd save the waypoints after a good lap you were happy with. You could have special waypoints that track positions while the rest look after the AI, all recordable by you playing your game.


Van-B


Next time he runs past, GRAB HIM!

Login to post a reply

Server time is: 2024-11-25 20:34:06
Your offset time is: 2024-11-25 20:34:06