Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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 3572 times)
0 Members and 1 Guest are viewing this topic.
Offline rdcarvallo

Senior Member


Projects: 5


2D Java games forever!


« Posted 2006-11-29 15: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.-


 
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 438
Projects: 4


Hand over your head.


« Reply #1 - Posted 2006-11-29 15: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 rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline rdcarvallo

Senior Member


Projects: 5


2D Java games forever!


« Reply #2 - Posted 2006-11-29 16: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!
Legends of Yore - The Casual Retro Roguelike
Offline ryanm
« League of Dukes »

Senior Member


Projects: 1


Used to be bleb


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

The behaviours on this page may be helpful.
Offline rdcarvallo

Senior Member


Projects: 5


2D Java games forever!


« Reply #4 - Posted 2006-11-29 20: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.-
Offline moogie

JGO Knight


Medals: 7
Projects: 5


Java games rock!


« Reply #5 - Posted 2006-11-30 00: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.

Offline rdcarvallo

Senior Member


Projects: 5


2D Java games forever!


« Reply #6 - Posted 2006-11-30 05: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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (70 views)
2013-05-17 21:29:12

alaslipknot (81 views)
2013-05-16 21:24:48

gouessej (111 views)
2013-05-16 00:53:38

gouessej (106 views)
2013-05-16 00:17:58

theagentd (117 views)
2013-05-15 15:01:13

theagentd (106 views)
2013-05-15 15:00:54

StreetDoggy (150 views)
2013-05-14 15:56:26

kutucuk (174 views)
2013-05-12 17:10:36

kutucuk (171 views)
2013-05-12 15:36:09

UnluckyDevil (180 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.118 seconds with 22 queries.