Java-Gaming.org Hi !
 Featured games (83) games approved by the League of Dukes Games in Showcase (542) Games in Android Showcase (133) games submitted by our members Games in WIP (604) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Home Help Search Login Register
Pages: [1]
 ignore  |  Print
 Car Driver AI  (Read 4426 times) 0 Members and 1 Guest are viewing this topic.
rdcarvallo

Senior Devvie

Projects: 5
Exp: 15 years

2D Java games forever!

 « Posted 2006-11-29 14:19:50 »

Hi,
I have been programming a road simulator/game, and I'm having problmes
with the driver's AI.
The game uses a tile map(with directed streets)

My algorithm has two parts:

Road Following:
-The driver knows the next 4 tiles the car will go. (tile 1 is the current tile where the car is)
-If there is a change in direction in the tiles 2 or 3, slows down the car
-For each step the dirver tries to mantain the car aligned with the road (tile direction).

Collision Avoidance:
-The driver look for cars near.
-If the car found is in front if the driver's car and in the next step the cars are nearer,  then slows down the car.

I still have problems on crossings, and the cars never stops completely. I want to include semaphores.

Do some of you have some pointers to info on programming car driver's AI??

Rafael.-

Riven
« League of Dukes »

« JGO Overlord »

Medals: 849
Projects: 4
Exp: 16 years

Hand over your head.

 « Reply #1 - Posted 2006-11-29 14:28:46 »

If every tile has a vector (2d) describing the direction (and speed, if the vector isn't normalized) the AI should be moving there, you can make it steer smoothly along corners, and make the AI get back on track after it was pushed off the road, or turn the car around etc etc. On crossings, you just set the vectors to 0,0 so that the AI will simply continue.

You can use the vectors to avoid moving obstacles too, by influencing the vectors behind/next to the opponents' cars.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
rdcarvallo

Senior Devvie

Projects: 5
Exp: 15 years

2D Java games forever!

 « Reply #2 - Posted 2006-11-29 15:48:43 »

Currently the tiles have flags for the exits, the driver selects one of
the exits(randomly) and uses ti to calculate the direction vector.

There is no speed info on the tilemap.

Using vectors for collision avoidance.. seems like using some kind
of repulsive potential field..
How can I take this info and represent it as steering commands??
The driver and the car are different entities, the car simulates the
physics and the driver interacts with the car using these 3 properties:
*acceleration
*brake
*steering angle

Rafael.-

EDIT: A screen from the editor.

 Games published by our own members! Check 'em out!
ryanm

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

 « Reply #3 - Posted 2006-11-29 16:33:49 »

The behaviours on this page may be helpful.
rdcarvallo

Senior Devvie

Projects: 5
Exp: 15 years

2D Java games forever!

 « Reply #4 - Posted 2006-11-29 19:31:54 »

Steering Behaviors..  The problem with them is that I don't know how to represent the
steering force as commands from the driver to the car..

Here are some screenies..

Rafael.-
moogie

JGO Ninja

Medals: 15
Projects: 6
Exp: 10 years

Java games rock!

 « Reply #5 - Posted 2006-11-29 23:59:47 »

Steering Behaviors..  The problem with them is that I don't know how to represent the
steering force as commands from the driver to the car..

Well, in my 2006 J4k entry (http://www.javaunlimited.net/results/view.php?id=104) I used steering behaviours to control the AI cars.

For the AI steering I calculated the angle between the cars' current direction vector and the 'desired' vector and based on this angle i commanded the car to rotate left or right.

Java4k RIP 2014
rdcarvallo

Senior Devvie

Projects: 5
Exp: 15 years

2D Java games forever!

 « Reply #6 - Posted 2006-11-30 04:12:17 »

The model of the car simulates the physics.. the car cannot be rotated directly, only applying the
torque of the friction forces of the wheels

The next image shows all the forces applied to the car.
red:aceleration (applied in the center of the axis (this car has front drive)
light green: friction of the rotationof the wheels
dark green: sliding friction of the wheells (always ortogonal to the wheel direction)
blue: current velocity

In this image, the car is turning (the driver send the command to turn the wheel to the right)
This produces a change in the forces applied.

Now I need to know how to send the right command to stop and avoid the collision. (As used in the separation behavior)

Rafael.-
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Add your game by posting it in the WIP section, or publish it in Showcase. The first screenshot will be displayed as a thumbnail.
 Elsealabs (15 views) 2014-12-28 10:39:27 CopyableCougar4 (18 views) 2014-12-28 02:10:29 BurntPizza (22 views) 2014-12-27 22:38:51 Mr.CodeIt (14 views) 2014-12-27 04:03:04 TheDudeFromCI (19 views) 2014-12-27 02:14:49 Mr.CodeIt (26 views) 2014-12-23 03:34:11 rwatson462 (58 views) 2014-12-15 09:26:44 Mr.CodeIt (47 views) 2014-12-14 19:50:38 BurntPizza (96 views) 2014-12-09 22:41:13 BurntPizza (115 views) 2014-12-08 04:46:31
 Rayvolution 50x BurntPizza 30x basil_ 29x HeroesGraveDev 25x LiquidNitrogen 22x appel 18x kpars 18x KevinWorkman 15x Riven 15x princec 14x NegativeZero 13x pitbuller 13x gouessej 13x SHC 12x KudoDEV 12x kevglass 11x
 How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27Resources for WIP games2014-08-01 16:20:17Resources for WIP games2014-08-01 16:19:50
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org