Hardoncollider goes crazy with third shape

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Wrinkliez
Prole
Posts: 33
Joined: Tue Mar 15, 2011 4:56 am

Hardoncollider goes crazy with third shape

Post 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?
Attachments
hardon_problem.love
Hardoncollider object getting stuck.
(18.91 KiB) Downloaded 138 times
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Hardoncollider goes crazy with third shape

Post 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.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
Wrinkliez
Prole
Posts: 33
Joined: Tue Mar 15, 2011 4:56 am

Re: Hardoncollider goes crazy with third shape

Post by Wrinkliez »

haha argh that makes so much sense. thanks man
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], slime and 1 guest