car AI

Non-platform specific questions.

car AI

Postby mrgame » Thu Jan 10, 2008 11:59 pm

im making a topdown car game and i need an AI code to make the other cars go round the track basicly.
ive tryed making some myself but they go glitchy and just start driving random places if they get hit by another car.

they must be able to be hit by other cars and carry on
i would love it so i could just put them on the track and they would drive round it.
im shore this will be hard but i bet someone can do it :) can you?
mrgame
 
Posts: 118
Joined: Sun Oct 21, 2007 8:09 pm
Location: my computer
Score: 3 Give a positive score

Re: car AI

Postby DilloDude » Fri Jan 11, 2008 3:43 am

This might not be particularly hard, but then it might not be too easy either. First of all, you need to know how the track goes. I would advise a system of waypoints. These can be just stored in variables. You'll want an array, with the size being the maximum number of points you want. For ease of saving and loading, you'll probably want four integer arrays in a savegroup. Alternatively, you could try using a string, and storing each int in two chars. Most convenient for use would be to make your own struct, but that wouldn't be so convenient to save. You'll want these four integers:
xpos: the x coordinate of the waypoint
ypos: the y coordinate of the waypoint
dir: the direction the waypoint faces
rad: the radius of the waypoint.
Each waypoint will cover a line. The x and y coordinates mark the centre of the line, the direction is perpendicular to the line in the way the track goes, and the radius is the distance from the centre to either end.
You'll need some way of setting up these waypoints initially, whether loading them from a file (you'll need someway of saving them there in the first place) or creating them in code. A file would be more convenient, but it depends on what your doing with the track.
Place a waypoint at each corner of the track (sharp corners may need several). The waypoint should be centred in the middle of the track. The direction should be so it spans straight across. The radius should take it to the edge of the track, or possibly just a little shorter. The first waypoint (index 0 in the array) should be right at the starting line. Waypoints should go all the way around the track 'til just before the start line (if it's a multi-lap course) or end at the finish line (for a single-lap course).

See what you can come up with using that, and then I'll work on using that to make the AI.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Re: car AI

Postby Bee-Ant » Fri Jan 11, 2008 10:26 am

how long reply :shock:
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron