Jump to content
  • Advertisement
Sign in to follow this  

Collision avoidance

This topic is 4523 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to make a 2d game where I have cars moving around between different way points. My problem is that I don't know how to make them avoid colliding with each other. If there is a car in front it should stop before they collide. Each car has 8 different frames and directions (N, NE, E, SE, S, SW, W, NW). I have a function to get the cars position and a function to stop the cars. Can anyone help me or give me a useful link? Thanks, nils.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by nils987
I'm trying to make a 2d game where I have cars moving around between different way points. My problem is that I don't know how to make them avoid colliding with each other. If there is a car in front it should stop before they collide.

Each car has 8 different frames and directions (N, NE, E, SE, S, SW, W, NW). I have a function to get the cars position and a function to stop the cars.



foreach (car1)
foreach (car2 != car1)
if InFrontOf(position(car2),position(car1),direction(car1)) the stop(car1)


InFrontOf(a,b,c) should determine if a occurs before b on the axis determines by c. This can be done by creating two orthogonal vectors based on the direction: one which has the direction, and one which is orthogonal to it. Express the coordinates of (a-b) on in this basis and checking that the colinear component is positive and smaller than a certain value, and that the orthogonal component is within a small zero-centered interval.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!