Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


avoid ships colliding?


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   -  Reputation: 584

Like
1Likes
Like

Posted 01 August 2014 - 07:08 AM

Hi

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.

 

Thanks

Erik



Sponsor:

#2 lightxbulb   Members   -  Reputation: 1141

Like
2Likes
Like

Posted 01 August 2014 - 09:26 AM

Google search:

http://gamedevelopment.tutsplus.com/tutorials/understanding-steering-behaviors-collision-avoidance--gamedev-7777

https://www.youtube.com/watch?v=Hc6kng5A8lQ

http://rocketmandevelopment.com/blog/steering-behaviors-flocking/



#3 ferrous   Members   -  Reputation: 2375

Like
0Likes
Like

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   -  Reputation: 2590

Like
5Likes
Like

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   -  Reputation: 584

Like
0Likes
Like

Posted 09 August 2014 - 07:42 AM

Cool!



#6 Orymus3   Crossbones+   -  Reputation: 12318

Like
0Likes
Like

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 Gones Done - Method and tools on how to start a hobby project and get it Done!

Retro Mortis - "RTS" - Article Series (3 Parts) on the history of RTS development


#7 flodihn   Members   -  Reputation: 254

Like
0Likes
Like

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 Mizmoon   Members   -  Reputation: 136

Like
0Likes
Like

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.



PARTNERS