Need help with collisions. STI and bump
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- meganukebmp
- Prole
- Posts: 8
- Joined: Thu Jan 07, 2016 10:38 pm
- Location: Sofia, Bulgaria
Need help with collisions. STI and bump
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
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: Need help with collisions. STI and bump
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".
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".
- meganukebmp
- Prole
- Posts: 8
- Joined: Thu Jan 07, 2016 10:38 pm
- Location: Sofia, Bulgaria
Re: Need help with collisions. STI and bump
Might I get a bit of explanation on this part of the code. I know it handles collisions but how?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".
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
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: Need help with collisions. STI and bump
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.
- meganukebmp
- Prole
- Posts: 8
- Joined: Thu Jan 07, 2016 10:38 pm
- Location: Sofia, Bulgaria
Re: Need help with collisions. STI and bump
No problems. So the world moves oposed to the player. Interesting.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.
Re: Need help with collisions. STI and bump
It's not that world:move means "move the world", it means "World [, container of all objects], move the player":meganukebmp wrote:No problems. So the world moves oposed to the player. Interesting.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.
Code: Select all
newx, newy, collisions = world:move( player, attempted_x, attempted_y )
- meganukebmp
- Prole
- Posts: 8
- Joined: Thu Jan 07, 2016 10:38 pm
- Location: Sofia, Bulgaria
Re: Need help with collisions. STI and bump
Aha. Got it. Thanks for explainingS0lll0s wrote:It's not that world:move means "move the world", it means "World [, container of all objects], move the player":meganukebmp wrote:No problems. So the world moves oposed to the player. Interesting.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.
Might be more understandable if you pretend :move is called :moveItemCode: Select all
newx, newy, collisions = world:move( player, attempted_x, attempted_y )
Who is online
Users browsing this forum: No registered users and 1 guest