Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

avoid ships colliding?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 suliman   Members   


Posted 01 August 2014 - 07:08 AM


I have a topdown 2d ww2 naval games with warships (destroyers, cruisers etc) running around (Think "navyfield" for the scale).

You Control a ship and have ai-controlled support ships, and the enemy has their ships (might be 10 ships in a fight)


Its realtime and no tiles, ships move "physics-based" taking time acc/deaccelarating, turning sluggishly (especially larger ships) but scale is rather arcadish so you can easily get close ("ram") other ships. Also ships need to go close to get within range for their guns. Each ship is controlled by turning and engine power.


So how do i make ai-ships avoid crashing into eachother/enemy ships? When facing other ships, if one turn and the other turns the same way they may just still crash into eachother (and so on...)


Im looking for a simple solution that works acceptably! Dont need to be perfect.




#2 lightxbulb   Members   


Posted 01 August 2014 - 09:26 AM

Google search:




#3 ferrous   Members   


Posted 01 August 2014 - 10:54 AM

One of the ai game programming wisdom books has a chapter on boats and steering, as well.  One of the earlier ones, 1-4, not the crazy expensive 5th one.

#4 IADaveMark   Moderators   


Posted 02 August 2014 - 12:27 AM


Cue Craig Reynolds

Edited by IADaveMark, 02 August 2014 - 12:28 AM.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC

Professional consultant on game AI, mathematical modeling, simulation modeling
Co-advisor of the GDC AI Summit
Co-founder of the AI Game Programmers Guild
Author of the book, Behavioral Mathematics for Game AI

Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

#5 suliman   Members   


Posted 09 August 2014 - 07:42 AM


#6 Orymus3   Members   


Posted 11 August 2014 - 08:48 AM

My simple system assumed an 'aura' around my ships. If it detected a ship within this range, it would seek the closest angle to rotate TOWARDS it, and move the opposite direction (overriding its regular steering until no ship was within that aura).


Some of the issues of this system:

- If there are two ships within range (one on either side of the helm), the ship would have a hard time breaking free, but assuming at least one of the others was also AI-driven (which it should, as this was a single player game), the other AI ship would break free first, giving the 2nd ship an angle of retreat.


- If there are just too many ships on the screen or the auras are too large, AI mayhem insues. So I had to balance the aura radius and the max amount of ships on screen accordingly.


Possibly far from the best solution to the problem, but it was simple and easy to devise, and it works good enough for my game (I don't think implementing anything better would have a better outcome and it is no longer bugging me).

-=- My Articles -=-
Getting Games Done - Method and tools on how to start a hobby project and get it Done!

The Art of Enemy Design in Zelda: A Link to the Past - Reverse-engineering functional enemy design from applied example.

Retro Mortis - "RTS" - Article Series (4 Parts) on the history of RTS development (4th part finally released!!!)


#7 flodihn   Members   


Posted 13 August 2014 - 01:18 AM

I created a long collision box shooting out from the ship, if that box collider with another I knew the ship was in risk of colliding in the future. Then you can take the other ships speed and compare to yours with the length of the collision in mind and you have a pretty good guess if collision will happen or not.


I also used an aura mention earlier but I only used that for evading incoming fire, since is usually only good for detecting things really close. 

Edited by flodihn, 13 August 2014 - 01:20 AM.

#8 khalvr   Members   


Posted 29 November 2014 - 06:50 PM

I was having the exact same problem once, and my solution was to give each ship an offset vector which represented how much the ship had to deviate from its course. The vector was zeroed at the start of each AI pass, and then you go through all neighboring ships in range, and add the vector between them and your ship scaled by a factor determined by their distance to you. This means that if there is another ship at both your left and your right, and they are at equal distances, the net offset will be zero. If there is one behind you and one to your left, the offset will be to your upper right, etc. If you need the offset as an angle, it is quite easily done with some trigonometry, followed by adding the offset angle to the facing of your ship to get the new facing. You might have a problem in the case where two ships are on your front left and right, and the best path would be to pass between them (while the offset vector points backwards), but it should be possible to fix with some exceptions.


Sorry for the semi-necropost, i hope it works out for you.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.