Collision response libraries

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
AaronWizard
Citizen
Posts: 68
Joined: Sun Nov 06, 2011 2:45 pm
Location: Canada

Collision response libraries

Post by AaronWizard »

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).
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Collision response libraries

Post by Taehl »

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.
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+.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Collision response libraries

Post by TechnoCat »

Taehl wrote:Hardon Collider is popular, but I think it doesn't do its own resolving.
It sort of does: http://vrld.github.com/HardonCollider/r ... tCallbacks
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.
But you can of course ignore it and roll your own.
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: Collision response libraries

Post by MarekkPie »

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.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Collision response libraries

Post by tentus »

Making objects respond as if they're solid in HardonCollider is about this hard:

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
Move the mouse over the circle to see it work.
Kurosuke needs beta testers
User avatar
AaronWizard
Citizen
Posts: 68
Joined: Sun Nov 06, 2011 2:45 pm
Location: Canada

Re: Collision response libraries

Post by AaronWizard »

Taehl wrote:Box2D (Love's native physics module) does resolving, too, though that may not be the tool you want.
I'd love to use Box2D if it wasn't for that physics bodies limit. :?
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.
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.

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?
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Collision response libraries

Post by TechnoCat »

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.
User avatar
AaronWizard
Citizen
Posts: 68
Joined: Sun Nov 06, 2011 2:45 pm
Location: Canada

Re: Collision response libraries

Post by AaronWizard »

TechnoCat wrote:If you would like, you can collect all the shapes colliding every frame and then do your own resolution.
But...that's the part I always suck at. :cry:
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: Collision response libraries

Post by MarekkPie »

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.
User avatar
AaronWizard
Citizen
Posts: 68
Joined: Sun Nov 06, 2011 2:45 pm
Location: Canada

Re: Collision response libraries

Post by AaronWizard »

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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 24 guests