Collision resolution with bump.lua

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
Janzo
Prole
Posts: 8
Joined: Sun Jul 31, 2016 1:20 am

Collision resolution with bump.lua

Post 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.
Attachments
donttouchtheceiling.love
(7.22 KiB) Downloaded 140 times
I'M SORRY, BUT DOES REALLY BOLD TEXT BOTHER YOU
palmettos
Prole
Posts: 14
Joined: Sun May 29, 2016 7:00 pm

Re: Collision resolution with bump.lua

Post by palmettos »

If the normal vector is {x = 0, y = 1} then the collision came from above the player.
palmettos
Prole
Posts: 14
Joined: Sun May 29, 2016 7:00 pm

Re: Collision resolution with bump.lua

Post 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.
Janzo
Prole
Posts: 8
Joined: Sun Jul 31, 2016 1:20 am

Re: Collision resolution with bump.lua

Post 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!
I'M SORRY, BUT DOES REALLY BOLD TEXT BOTHER YOU
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests