Page 1 of 1

Collision resolution with bump.lua

Posted: Thu Aug 04, 2016 4:55 pm
by Janzo
I finally figured out collisions with bump.lua, but now im having trouble with the resolution of the collisions. I have it so my player item collides with the floor and walls, but i want to make it so if the ceiling collides with the player, the game quits with love.event.quit().
here is the project so far.
Is there a way to check if my player collides with my ceiling and quit the game int hat event, but if it hits the floor or wall it just collides normally? thank you.

Re: Collision resolution with bump.lua

Posted: Thu Aug 04, 2016 9:01 pm
by palmettos
If the normal vector is {x = 0, y = 1} then the collision came from above the player.

Re: Collision resolution with bump.lua

Posted: Fri Aug 05, 2016 12:26 am
by palmettos
I had some time to sit down and write the code for what I meant. You could do this at line 43 in your player.lua to see if any of the collisions came from above the player:

Code: Select all

	local cols
	player.x, player.y, cols = world:move(player, player.x + player.dx, player.y + player.dy)
	for _, col in ipairs(cols) do
		if col.normal.y >= 1 then
			love.event.quit()
		end
	end
The normal vector represents the direction from which the other tile collided with the object you're moving in the bump world.

Re: Collision resolution with bump.lua

Posted: Fri Aug 05, 2016 2:59 am
by Janzo
palmettos wrote:I had some time to sit down and write the code for what I meant. You could do this at line 43 in your player.lua to see if any of the collisions came from above the player:

Code: Select all

	local cols
	player.x, player.y, cols = world:move(player, player.x + player.dx, player.y + player.dy)
	for _, col in ipairs(cols) do
		if col.normal.y >= 1 then
			love.event.quit()
		end
	end
The normal vector represents the direction from which the other tile collided with the object you're moving in the bump world.
Ah, this helps. Thank you very much!