Page 1 of 1

Hardoncollider goes crazy with third shape

Posted: Wed Feb 13, 2013 6:54 pm
by Wrinkliez
So I was playing around with hardoncollider the other day, and I found this weird issue. With two shapes colliding, everything works beautifully. But whenever I add a third shape, even if it's nowhere near the other two, the collision goes crazy, with shapes getting caught in each other.

I'm thinking that it has something to do with the separating vector, but I'm not really sure how that works.

I've uploaded a .love. If you move the smaller circle into the square, you should see it get caught. (Although, I've noticed it only does it like 2/3rds of the time :? )

If you go into the code, you can comment out the two lines that create the extra shape, and see the collision go back to working perfectly.

Any ideas?

Re: Hardoncollider goes crazy with third shape

Posted: Wed Feb 13, 2013 9:52 pm
by vrld
The separation vector always points in the direction shape_a has to be moved to resolve the collision, so you have to flip it if player is shape_b instead of shape_a. I.e. `on_collision()' should look like this:

Code: Select all

function on_collision(dt, shape_a, shape_b, mtv_x, mtv_y)
	if shape_a == player_bounding_box then
		player_collide_with_post(shape_a, mtv_x, mtv_y)
	elseif shape_b == player_bounding_box then
		player_collide_with_post(shape_b, -mtv_x, -mtv_y) --< vector flipped
	end
end
Unrelated, but it bugs me: In `player_collide_with_post()', the two move calls should be combined into just one.

Re: Hardoncollider goes crazy with third shape

Posted: Fri Feb 15, 2013 12:04 am
by Wrinkliez
haha argh that makes so much sense. thanks man