🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Square circle collision

Started by
3 comments, last by Calin 2 weeks, 2 days ago

Does it take a ton of math to figure out when a circle and square collide? I could use two collision bodies for each unit, a circle and a square, I could then use the square for when a unit collides with a rectangle obstacle and the circle to collide against other units. It’s a solution but if a unit collides with a rectangle obstacle it would get stuck in place. It would be nice to have a sliding effect against the rectangle obstacle walls when other circles are pushing from the sideways. The rectangle obstacle should cause a bounce back for that to happen.

My project`s facebook page is “DreamLand Page”

Advertisement

Calin said:
Does it take a ton of math to figure out when a circle and square collide?

No.

For objects motion you also might want to consider using swept tests (which might be necessary to properly implement sliding effects).

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

@Calin See if this post helps:

https://www.gamedev.net/forums/topic/715762-how-does-swept-aabb-collision-work-in-3d-space-with-objects-of-different-sizes/5462310/

If I understand your desire to have a sliding effect, it's not too hard. Consider a circle approaching a wall at a 45° Angle. When they collide, you don't want the circle to stop, but move along the wall..

You need to break down the circle's velocity into two components. The first component would be in the direction that's orthogonal to the wall. If you subtract this component from the circle's velocity, you're left with the direction that goes along the wall.

Thank you guys. I made the thread foremost because I didn’t know how to detect circle square collisions. I think I have it figured now.

My project`s facebook page is “DreamLand Page”

Advertisement