• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# Pedestrian collision avoidance (vectors)

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

## Recommended Posts

Hi, Im writing a small game with pedestrians in it, they currently walk around the sidewalk / pavements using waypoints. I have been trying to get collision avoidance coded for about a week but the maths keeps killing me The collision detection routine works by every pedestrian creating a 1/2 meter circle (in 2D space) 2 meters infront of the pedestrian. Every pedestrian tests for a collision between these ''collision circles'' if a collision occurs a vector between the centers of the circles in worked out.. Now what I think I need to do is to rotate this vector by 90 degrees, so instead of the collision pointing towards to other circle it points away. That means the pedestrians will miss each other when rotated towards that new vector.. I cant get the vector maths correct, it seems to work for pedestrians walking West to East OK, but Pedestrians walking North to South turn wrongly.. I`m think I need to do something with the forward vector but my minds so fried that I think I need some fresh eyes to look at this Can anyone suggest an (easier?) way to do work out how to convert the ''collision vector'' to an ''avoidance vector''? Thanks for any help, its GREATLY appreciated!! James.

##### Share on other sites
Use flocking. This is what it''s for.

Give each user a direction vector to start with (towards their current goal), then add in a ''force'' that repels them from other pedestrians, which directly modifies their direction vector. They''ll all just magically avoid each other.

##### Share on other sites
Im guessing you have a 90 degree rotation which involves cos(angle) and sin(angle) and one of them is OK but the other needs multiplying by -1.

But that''s just a hunch, of course

• ### What is your GameDev Story?

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

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

• Total Topics
634084
• Total Posts
3015403
×