Page 1 of 1
Need help with collisions. STI and bump
Posted: Thu Jan 07, 2016 11:25 pm
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
Re: Need help with collisions. STI and bump
Posted: Thu Jan 07, 2016 11:49 pm
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".
Re: Need help with collisions. STI and bump
Posted: Fri Jan 08, 2016 8:56 am
by meganukebmp
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
Re: Need help with collisions. STI and bump
Posted: Fri Jan 08, 2016 11:55 am
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.
Re: Need help with collisions. STI and bump
Posted: Fri Jan 08, 2016 4:20 pm
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.
Re: Need help with collisions. STI and bump
Posted: Fri Jan 08, 2016 6:38 pm
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
Re: Need help with collisions. STI and bump
Posted: Fri Jan 08, 2016 10:25 pm
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