Page 1 of 1
Wall and floor collision
Posted: Tue Nov 29, 2022 3:57 pm
by fridays18
Ive been using love2d for a bit and the way ive done collision is just like
Code: Select all
if key == "up" then
if player.y > 0 then
player.y = player.y + player.speed * dt
end
end
but now that im trying to branch out into things like actual level design with multiple objects rather than just a general boarder, can someone point me in the right direction on where to learn how to do this, ive been trying to use bump but despite the tons of documentation on it its still kinda hard to actually understand how its collision system works so Ive been a bit lost on this topic. Any help is appreciated
NOTE: I know how to do general collision detection just not how to link that to wall / level collision since ive only ever used it for entity / item / bullet collision
Re: Wall and floor collision
Posted: Tue Nov 29, 2022 4:09 pm
by fridays18
Little demo I made
Code: Select all
for i,v in ipairs(walls) do
check = CheckCollision(player.x ,player.y ,player.w ,player.h ,v.x ,v.y ,v.w ,v.h )
if check == false then
if love.keyboard.isDown("a") then
player.x = player.x - player.speed * dt
elseif love.keyboard.isDown("d") then
player.x = player.x + player.speed * dt
elseif love.keyboard.isDown("w") then
player.y = player.y - player.speed * dt
elseif love.keyboard.isDown("s") then
player.y = player.y + player.speed * dt
end
end
end
its checking if the player values collide with a box class I made, only issue is I dont know how to make this so that the player wont just stop moving
Re: Wall and floor collision
Posted: Tue Nov 29, 2022 4:22 pm
by fridays18
Update
Code: Select all
for i,v in ipairs(walls) do
checkTop = CheckCollision(player.x ,player.y ,player.w ,player.h ,v.x ,v.y ,v.w ,1 )
checkBottom = CheckCollision(player.x ,player.y ,player.w ,player.h ,v.x ,v.y + v.h ,v.w ,1 )
checkLeft = CheckCollision(player.x ,player.y ,player.w ,player.h ,v.x ,v.y ,1 ,v.h )
checkRight = CheckCollision(player.x ,player.y ,player.w ,player.h ,v.x + v.w ,v.y ,1 ,v.h )
if love.keyboard.isDown("a") then
if checkRight == false then
player.x = player.x - player.speed * dt
end
elseif love.keyboard.isDown("d") then
if checkLeft == false then
player.x = player.x + player.speed * dt
end
elseif love.keyboard.isDown("w") then
if checkBottom == false then
player.y = player.y - player.speed * dt
end
elseif love.keyboard.isDown("s") then
if checkTop == false then
player.y = player.y + player.speed * dt
end
end
end
this code checks through all the box class and checks each of the boxs dimensions and gets a collision based off that. this sytem works perfectly...unless theres more than one box since it looping based on how many box's there are so if theres 2 box's the player does their movements 2x