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.

DarkBASIC Discussion / How the do I calculate track positions?

Author
Message
Doucan
21
Years of Service
User Offline
Joined: 26th Nov 2003
Location: Vermont USA
Posted: 31st Jan 2004 16:40
I've been trying to make a racing game for some time. Everyone seems to know how to do this but me!

My problem is that I can't figure out the the code to find a car's position on the course. I've looked in the code snippets and there's nothing there.

Please help...

Doucan...

Completed Doucan movies: Doucan year of the Monkey, Doucan II: the revenge of Mortakia. Current project: Doucan movie DVD resoration. Progress: 20%
Travis
21
Years of Service
User Offline
Joined: 9th Nov 2003
Location: West Aust.
Posted: 1st Feb 2004 14:54
what do u mean? find the position in x,y,z or as how far around the track it is? or what

object position x()
object position y()
object position z()

dont just try to look/copy other ppl's code try reading thro the help files look under commands/basic 3d
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 2nd Feb 2004 04:19
Also, a little while ago ( about a week, maybe a bit less ), there was a thread on way points... Have a look there, and you might be able to solve your problem.

Also, have a look through the help files... They're realy quite good.

Hope I Helped...
Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Doucan
21
Years of Service
User Offline
Joined: 26th Nov 2003
Location: Vermont USA
Posted: 4th Feb 2004 03:33
I'm trying to calculate the player's position in relation to the
compedtitors; who's ahead of who.

Completed Doucan movies: Doucan year of the Monkey, Doucan II: the revenge of Mortakia. Current project: Doucan movie DVD resoration. Progress: 20%
BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Feb 2004 10:43
You could base it on waypoints, and distance between waypoints. That is, order the racers by the waypoint they have reached, and then within that, how close they are to the next waypoint.

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 4th Feb 2004 11:07
Yeah, waypoints are the way to go.

A good way to manage waypoints is distance - say you had 100 waypoints, like a pearl necklace around the track. You'd have a current waypoint, and check for the car being inside a set distance. When the checkpoint is reached, you go onto the next waypoint. This can be used for AI to an extent, you would have to use secondary path finding too.

Using this method you could also detect corner cutting, going the wrong way, etc etc because you can check if the distance between the car and waypoint is growing (going away from) or shrinking (getting closer to). To guage the track distance, you have the current waypoint of each car - and can calculate the distance from the current waypoint - if 2 cars are heading towards the current waypoint, the closest car is in the lead.

You'll probably have to use some sort of system, maybe having inbetween waypoints to aid the AI, because it could be easy to loose track when theres a section of track with uneven waypoints.

Recently I used a similar system to take a tour of a memblock tunnel, and it worked quite well for that - I was able to use better waypoint detection, because your always going forward - you check the distance, if the distance shortens then your heading towards it, if it lengthens then your past it, I just wait till the distance lengthens then go onto the next waypoint. Practically impossible to miss one - unfortunately this would'nt work with a racing game because your moving forward and back. Might give you an idea for better waypoint detection though.

The waypoints can serve more than AI and position detection though - they could be used to tell the player what degree of corner is comming up, speeds to take the corners etc.

One last thing - if you need to discover what waypoint the car is at - you could just check the distance between the car and all the waypoints, that'll tell you the closest one.


Van-B


The nature of Monkey was irrepressible!.
BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Feb 2004 18:11
Quote: "One last thing - if you need to discover what waypoint the car is at - you could just check the distance between the car and all the waypoints, that'll tell you the closest one."


But be careful! If your track is continous (e.g round, oval, oblong, figure of eight etc...) you may be legitimately closer to a waypoint other than the one you're heading for.

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
Doucan
21
Years of Service
User Offline
Joined: 26th Nov 2003
Location: Vermont USA
Posted: 5th Feb 2004 01:36
I had toyed with the waypoint a I dea but as I am not a very expeienced programmer have never written the code. The only problem I thought of was the one BatVink mentioned

Doucan...

Completed Doucan movies: Doucan year of the Monkey, Doucan II: the revenge of Mortakia. Current project: Doucan movie DVD resoration. Progress: 20%
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 5th Feb 2004 10:21
That's the whole point of using a string of waypoints around the track. Checking for the current waypoint was something I mentioned, but you don't need to do it that way - if you assign the next waypoint everytime the current waypoint is reached, it would know where the player should be on the track. So even if your heading toward waypoint 50 and waypoint 20 is further away, you'd still need to go past waypoint 20, the system would totally ignore waypoint 50 (you probably would'nt do a distance check on anything but the next waypoint).
You could use visual aids, like an arrow pointing in the right direction for when the next checkpoint is not in screen. If you missed a checkpoint, it would want you to go back and go through it again, but that'd mostly be because the player cut the corner.


Van-B


The nature of Monkey was irrepressible!.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Feb 2004 12:01
By using the good old distance formula, its possible to do this by only having to place a waypoint at a bend in the track.

"eureka" - Archimedes
BatVink
Moderator
22
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Feb 2004 14:11
I love Waypoint discussions

My app is still well under development, but I anticipate having more Waypoints than just for cornering. I can see all sorts of good uses, such as narrowing the track width on a straight to create a bottle neck. That would create a new "Buzz", fighting for the best position where there's only room for one vehicle.

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php

Login to post a reply

Server time is: 2025-05-22 11:13:32
Your offset time is: 2025-05-22 11:13:32