Jump to content
• ### What is your GameDev Story?

• Advertisement

# Collision avoidance

This topic is 4765 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

##### Share on other sites
Advertisement
Quote:
 Original post by nils987I'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

##### Share on other sites

• Advertisement
• Advertisement
• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• ### Popular Now

• 10
• 11
• 13
• 9
• 11
• Advertisement
• ### Forum Statistics

• Total Topics
634092
• Total Posts
3015447
×

## Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!