Need help with collisions. STI and bump

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
meganukebmp
Prole
Posts: 8
Joined: Thu Jan 07, 2016 10:38 pm
Location: Sofia, Bulgaria

Need help with collisions. STI and bump

Post by meganukebmp »

Hello so I am using STI to load a tiled map and bump for collisions. Sadly STI's bump plugin documentation is none. I did a bunch of guesswork and achieved nothing. Then I stumbled upon the demo in the attachments and tried using parts of its code but to no avail. Can someone please help me understand how all of this works. A git of the project is available here: https://github.com/meganukebmp/Soul-Shift
Attachments
collisions.love
The demo I tried using code from. PS: I do not own this code. All credit goes to its author
(54.64 KiB) Downloaded 176 times
SoulShift.love
The thing I am working on.
(888.7 KiB) Downloaded 147 times
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Need help with collisions. STI and bump

Post by bobbyjones »

https://github.com/Bobbyjoness/Boredom/ ... r/main.lua

Here is a small example. To get it to work in 0.10.0 you just have to change the "l" in mousepressed to "1".
User avatar
meganukebmp
Prole
Posts: 8
Joined: Thu Jan 07, 2016 10:38 pm
Location: Sofia, Bulgaria

Re: Need help with collisions. STI and bump

Post by meganukebmp »

bobbyjones wrote:https://github.com/Bobbyjoness/Boredom/ ... r/main.lua

Here is a small example. To get it to work in 0.10.0 you just have to change the "l" in mousepressed to "1".
Might I get a bit of explanation on this part of the code. I know it handles collisions but how?

Code: Select all

player.xvel = player.xvel - 50
	
	player.yvel = player.yvel + GRAVITY

	if player.xvel > player.maxVelocityX then player.xvel = player.maxVelocityX end

	if player.xvel < 0 then player.xvel = 0 end

	player.x = player.x + player.direction*player.xvel*dt

	player.y = player.y + (player.yvel)*dt

	player.x, player.y, cols = world:move( player, player.x, player.y )

	for i,v in ipairs (cols) do
		if cols[i].normal.y == -1 then
			player.yvel = 0
			player.grounded = true
			debug = debug.."Collided "
		elseif cols[i].normal.y == 1 then
			player.yvel = -player.yvel/4
		end
		if cols[i].normal.x ~= 0 then
			player.xvel = 0
		end
	end
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Need help with collisions. STI and bump

Post by bobbyjones »

world:move will move an object to a specified x and y. If the object collides along the way it will return the new x and y along with a collision list (cols) I then get the normal so that I can edit my velocity correctly. The rest is just regular movement code. I apologize if I explained poorly. I'm on my phone. I will write up a better explanation later if you need it.
User avatar
meganukebmp
Prole
Posts: 8
Joined: Thu Jan 07, 2016 10:38 pm
Location: Sofia, Bulgaria

Re: Need help with collisions. STI and bump

Post by meganukebmp »

bobbyjones wrote:world:move will move an object to a specified x and y. If the object collides along the way it will return the new x and y along with a collision list (cols) I then get the normal so that I can edit my velocity correctly. The rest is just regular movement code. I apologize if I explained poorly. I'm on my phone. I will write up a better explanation later if you need it.
No problems. So the world moves oposed to the player. Interesting.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Need help with collisions. STI and bump

Post by s-ol »

meganukebmp wrote:
bobbyjones wrote:world:move will move an object to a specified x and y. If the object collides along the way it will return the new x and y along with a collision list (cols) I then get the normal so that I can edit my velocity correctly. The rest is just regular movement code. I apologize if I explained poorly. I'm on my phone. I will write up a better explanation later if you need it.
No problems. So the world moves oposed to the player. Interesting.
It's not that world:move means "move the world", it means "World [, container of all objects], move the player":

Code: Select all

newx, newy, collisions = world:move( player, attempted_x, attempted_y )
Might be more understandable if you pretend :move is called :moveItem

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
meganukebmp
Prole
Posts: 8
Joined: Thu Jan 07, 2016 10:38 pm
Location: Sofia, Bulgaria

Re: Need help with collisions. STI and bump

Post by meganukebmp »

S0lll0s wrote:
meganukebmp wrote:
bobbyjones wrote:world:move will move an object to a specified x and y. If the object collides along the way it will return the new x and y along with a collision list (cols) I then get the normal so that I can edit my velocity correctly. The rest is just regular movement code. I apologize if I explained poorly. I'm on my phone. I will write up a better explanation later if you need it.
No problems. So the world moves oposed to the player. Interesting.
It's not that world:move means "move the world", it means "World [, container of all objects], move the player":

Code: Select all

newx, newy, collisions = world:move( player, attempted_x, attempted_y )
Might be more understandable if you pretend :move is called :moveItem
Aha. Got it. Thanks for explaining :)
Post Reply

Who is online

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