I've seen libraries here for collision detection, but has anyone put something together for collision response?
I'm envisioning a library that you can feed objects to and, after an update function call, all moving objects are updated with sensical positions and you are allowed to give any objects involved in a collision a new velocity through a callback.
I've been trying the built-in physics engine, but I was hitting the limit on the number of bodies just for the wall tiles (game will be a top-down shooter). Even when I only make bodies for the edge wall tiles I'm only left with a limit of 500 or so for enemies and bullets (the total limit is 2048 apparently).
Collision response libraries
- AaronWizard
- Citizen
- Posts: 68
- Joined: Sun Nov 06, 2011 2:45 pm
- Location: Canada
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Collision response libraries
Fizz and Fizz X are like that. Box2D (Love's native physics module) does resolving, too, though that may not be the tool you want.
Hardon Collider is popular, but I think it doesn't do its own resolving.
Hardon Collider is popular, but I think it doesn't do its own resolving.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- TechnoCat
- Inner party member
- Posts: 1612
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: Collision response libraries
It sort of does: http://vrld.github.com/HardonCollider/r ... tCallbacksTaehl wrote:Hardon Collider is popular, but I think it doesn't do its own resolving.
But you can of course ignore it and roll your own.vrld wrote:mtv_x and mtv_y define the minimum translation vector, i.e. the direction and magnitude shape_one has to be moved so that the collision will be resolved.
Re: Collision response libraries
Response is a bit more specific per game than detection is. Do I want two asteroids to bounce off one another on collision, or do I want them to shatter? Do I want a projectile to destroy a whole plane, or do I want it to change its trajectory? I think that's why there isn't as much in the response category.
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Collision response libraries
Making objects respond as if they're solid in HardonCollider is about this hard:
Move the mouse over the circle to see it work.
Code: Select all
function love.load()
collider = require("hardoncollider")(128, on_collide)
shapes = {
collider:addCircle(100, 100, 25),
collider:addCircle(200, 200, 50),
}
end
function love.update(dt)
shapes[1]:moveTo(love.mouse.getPosition())
collider:update(dt)
end
function love.draw()
for i=1, #shapes do
shapes[i]:draw("line")
end
end
function on_collide(dt, a, b, x,y)
a:move(x,y)
end
Kurosuke needs beta testers
- AaronWizard
- Citizen
- Posts: 68
- Joined: Sun Nov 06, 2011 2:45 pm
- Location: Canada
Re: Collision response libraries
I'd love to use Box2D if it wasn't for that physics bodies limit.Taehl wrote:Box2D (Love's native physics module) does resolving, too, though that may not be the tool you want.
For me the hard part isn't the "what's their new velocities" part. It's the "how do I separate these overlapping objects" part. The part where I have to handle edge cases like an object bumping against two walls at the same time. Or cases like objects A, B, and C are overlapping each other, and I can't just move them backwards because object D just moved to where B used to be. My dream library would make sure all these objects are separated, and when collisions did occur it would allow me to set new velocities for the colliders. Or allow me to destroy one or both colliders to handle Asteroids.MarekkPie wrote:Response is a bit more specific per game than detection is. Do I want two asteroids to bounce off one another on collision, or do I want them to shatter? Do I want a projectile to destroy a whole plane, or do I want it to change its trajectory? I think that's why there isn't as much in the response category.
How does HardonCollider's minimum translation vector work. Is it just for the two objects involved in the collision, ignoring all other objects around them?
- TechnoCat
- Inner party member
- Posts: 1612
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: Collision response libraries
Only for the 2 objects colliding passed into the callback. If you would like, you can collect all the shapes colliding every frame and then do your own resolution. Effectively ignoring mtv_y and mtv_x.
- AaronWizard
- Citizen
- Posts: 68
- Joined: Sun Nov 06, 2011 2:45 pm
- Location: Canada
Re: Collision response libraries
But...that's the part I always suck at.TechnoCat wrote:If you would like, you can collect all the shapes colliding every frame and then do your own resolution.
Re: Collision response libraries
Again, going off the assumption that Hardon uses SAT, (which it looks like it does with all the references to convex polygons), here's a good visual tutorial that shows how SAT provides a minimum translation vector. Look at the arrows formed, and how one arrow gets highlighted when there is a collision.
- AaronWizard
- Citizen
- Posts: 68
- Joined: Sun Nov 06, 2011 2:45 pm
- Location: Canada
Re: Collision response libraries
The minimum translation vector thing makes sense when it's just two objects that are colliding, or if objects only collide with the immobile terrain. But handling collisions between three or more objects is something I can't get my head around. And something I've never seen explained well on the Internet.
Who is online
Users browsing this forum: Bing [Bot] and 9 guests