Jump to content
  • Advertisement
Sign in to follow this  

Handling collisions

This topic is 4078 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 just finished writing up a simple collision detection algo for my 2d game. the problem is, I'm not sure what to do once I know 2 units are colliding. I need to find some efficient and fail-safe way to determine which way the unit needs to move once it collides with another unit (or building,tree,rock, whatever). For example Unit A is going from its starting position to its final one, but Unit B is in the way. Once they collide, I need to know which way for A one to go to get around B:
 Final Destination

                        _Unit B
                       |_| _
                     *2   |_| Unit A
                                **Started Here
Does A go to 1 or 2? And how would it decide? [Hopefully this isn't to confusing] Is the only fail-safe way to do this is implement some pathfinding routine like A*? Any help or useful sites would be much appreciated. Jeff

Share this post

Link to post
Share on other sites
This has little to do with collision-detection, or even handling. Collision detection only checks if objects collide. Collision handling pushes them out if they're both solid, and/or notifies them of the collision, the low-level work that needs to happen after a collision.

Where A should go is a higher-level decision. Pathfinding would be more appropriate here, yeah. You may also want to look into flocking behaviour, especially how to make objects repel each other. Which approach you should take - perhaps a mix of these, or a totally different approach - depends on what you want to use this for.

EDIT: This just came to my mind, you could project B onto a normal of the line between A and A's destination, and check on which side it sticks out least - you then set that corner as an intermediate destination for A, and repeat the process untill A has arrived safely. I don't know if that will work for every shape or every situation, but it's an idea. Or you could use this to generate a nodegraph and then do pathfinding on it... just some idea's.

Share this post

Link to post
Share on other sites
Thanks for the reply and the input.

I had thought about doing your recomendation of setting a corner of the barrier as an intermediate goal. I will need to implement some kind of pathfinding technique eventually, probably A*. I thought about doing this:
When a Unit's destination is set, the Unit will move directly to that spot. If it hits a barrier, then it will compute the best path. I'm kinda hoping this will eliminate the number of computations needed to be done, as many Unit's moves in an RTS can be done without going around something.

However, it seems to me that Unit to Unit collision should be handled differently. I think for now I'll try to find which side of the destination the barrier lies on, and then move accordingly.


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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!