Jump to content
  • Advertisement
Sign in to follow this  
Oatskits

How to react to collision among entities chasing the player

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

In my top-down 2d game, I have a bunch of enemies that find a straight line between them and the player and chase him around. It works fine, but after a little while all of the entities end up merging together and it looks as if there is just 1. I've tried numerous methods on how to react to two of the entities colliding, but can't get the effect I want. How do I make the entities just kind of bundle next to each other rather than all moving to the exact same spot? Thanks to any one who can help!

Share this post


Link to post
Share on other sites
Advertisement
I'm afraid you'll need to check them all for collisions between themselves.
The idea is to just move them, resolve collision, avoid encroaching. For each tick. This implies the enemies won't stand where they are supposed to be, hopefully this is not a problem.

If using a collision API, I suggest to not do that in the first place and just use physics-based, fully simulated entities. Working with forces and speeds sometimes appears as counter-intuitive, but having a single system has some advantages.

Share this post


Link to post
Share on other sites
Collision is important, but with just collision all the enemies will still bunch together. There could be a "traffic jam" where enemies cannot pass each other, leading to large stationary clumps that take a while to dissipate.

This might be fine if the enemies are supposed to be totally mindless, like zombies or something. But if you want them to look a little smarter, you should also look into flocking algorithms, AKA "boids" simulators. These allow a group of actors to follow a common line while trying to remain physically separate - like a flock of real birds.

Share this post


Link to post
Share on other sites
You should be able to figure out, for each enemy, that if he doesn't slow down he's going to bump into his colleague; and have rules for precedence (e.g. younger entities yield to older entities of the same type, fast unit types yield to slower unit types, large marching columns yield to small patrols, everybody yields to gigantic beam weapon fire, and so on).
Note that you don't need precise collision prediction; as long as units don't behave too inefficiently you can err on the conservative side (e.g. ignore actual shapes and use AABBs).

Every units should be able to decide whether it has precedence or not; and consequently to go on, confident that other units will avoid collisions, or to slow down and treat the colleague as an obstacle to walk around.
This is fairly independent from the type of pathfinding (direct towards an objective or following/flocking with other units); in any case, the unit that avoids a collision has a desired but unsafe velocity for its position and a corrected (reduced or diverted) safe velocity that will be used instead.

Collisions between enemies should be as rare as collisions between pedestrians in the street: support them just to be safe, or maybe for unfavourable special cases in which units could move too fast to avoid collisions.

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.

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!