Page 1 of 3
Avoiding moving objects going into walls in bump.lua
Posted: Mon Mar 08, 2021 12:26 pm
by Gunroar:Cannon()
Sometimes when I use bump.lua and 2 moving objects come in contact with each other and one pushes the other to a wall it goes inside the wall and keeps moving through the wall until it comes out of to empty space. This happens in general when I use bump.lua, it's not in specific projects.
Does anyone know how to fix this like a code to stop it from happening?
Re: Avoiding moving objects going into walls in bump.lua
Posted: Mon Mar 08, 2021 4:27 pm
by darkfrei
Gunroar:Cannon() wrote: ↑Mon Mar 08, 2021 12:26 pm
Sometimes when I use bump.lua and 2 moving objects come in contact with each other and one pushes the other to a wall it goes inside the wall and keeps moving through the wall until it comes out of to empty space. This happens in general when I use bump.lua, it's not in specific projects.
Does anyone know how to fix this like a code to stop it from happening?
Is bump.lua your own file?
Re: Avoiding moving objects going into walls in bump.lua
Posted: Mon Mar 08, 2021 5:05 pm
by eliddell
He means this, I think:
https://github.com/kikito/bump.lua
It sounds like objects are not being tested for collisions during sliding/recoil (or you don't have the additional collisions set up). This may be internal to the library. You could switch to the "touch" type of collision, which doesn't have recoil. Or you could implement your own collision response handler, which does the checks you need (read the "Advanced API" section of the bump.lua readme). Or switch to another library, possibly HC. Or wait for someone else to come up with a better idea.
Re: Avoiding moving objects going into walls in bump.lua
Posted: Mon Mar 08, 2021 6:46 pm
by Gunroar:Cannon()
Thnx for replies...
eliddell wrote: ↑Mon Mar 08, 2021 5:05 pm
He means this, I think:
https://github.com/kikito/bump.lua
It sounds like objects are not being tested for collisions during sliding/recoil (or you don't have the additional collisions set up). This may be internal to the library.
So, does it not check for collisions when bump makes it recoil, which could make it recoil into an object next to it, in the code for world:move()?
Also, whenever I use touch the object always gets stuck to what it touched, is that just for me or is this normal behaviour that can be changed?
Re: Avoiding moving objects going into walls in bump.lua
Posted: Mon Mar 08, 2021 7:07 pm
by pgimeno
I don't think bump can push objects in the first place, so the problem is probably on your side.
Re: Avoiding moving objects going into walls in bump.lua
Posted: Tue Mar 09, 2021 12:10 am
by MrFariator
This sounds like a code issue more than an issue with the library. You'll have to share your code, because I could see several cases where what you could describe happens, and it all boils down to how you're handling the collision responses, and what kind of filters you're using.
Gunroar:Cannon() wrote: ↑Mon Mar 08, 2021 6:46 pm
Also, whenever I use touch the object always gets stuck to what it touched, is that just for me or is this normal behaviour that can be changed?
"Touch" does exactly what it says on the tin: it stops moving the object as soon as it detects a "touch" collision. For example, if your object has gravity applied that moves it downwards continuously, but the collision with the floor causes a "touch" event - the object will effectively be glued to the floor until it starts moving away, or at a parallel angle to it.
Re: Avoiding moving objects going into walls in bump.lua
Posted: Tue Mar 09, 2021 9:50 pm
by Gunroar:Cannon()
Thnx for all replies...
MrFariator wrote: ↑Tue Mar 09, 2021 12:10 am
This sounds like a code issue more than an issue with the library. You'll have to share your code, because I could see several cases where what you could describe happens, and it all boils down to how you're handling the collision responses, and what kind of filters you're using.
pgimeno wrote: ↑Mon Mar 08, 2021 7:07 pm
I don't think bump can push objects in the first place, so the problem is probably on your side.
Yeah, you're right, I checked inside the file and didn't see anything that pushes the object.
Here's the part or the code that moves the entity:
Code: Select all
function Entity:applyImpulseY(imp)
self.vy = self.vy + imp
--self:set("vy","+",imp)
end
function Entity:applyImpulseX(imp)
self.vx = self.vx + imp
--self:set("vx","+",imp)
end
function Entity:applyImpulse(impX,impY)
self:applyImpulseX(impX)
self:applyImpulseY(impY)
end
function Entity:changeVelocityByImpulse(col)
local other = col.other
if not other.isTile then
--push
local y,x = col.normal.y, col.normal.x
if y<0 and self.vy>other.vy then
other:applyImpulseY(self.vy)
elseif y<0 and self.vy<other.vy then
self:applyImpulseY(other.vy)
end
if y>0 and self.vy<other.vy then
other:applyImpulseY(self.vy)
elseif y>0 and self.vy>other.vy then
self:applyImpulseY(other.vy)
end
if x<0 and self.vx>other.vx then
other:applyImpulseX(self.vx)
elseif x<0 and self.vx<other.vx then
self:applyImpulseX(other.vx)
end
if x>0 and self.vx<other.vx then
other:applyImpulseX(self.vx)
elseif x>0 and self.vx>other.vx then
self:applyImpulseX(other.vx)
end
end
end
function Entity:changeVelocityByCollisionNormal(nx, ny, bounciness)
local bounciness = bounciness or self.elasticity
if not bounciness or bounciness == 0 then
return
end
local vx, vy = self.vx, self.vy
if (nx < 0 and vx > 0) or (nx > 0 and vx < 0) then
vx = -vx * bounciness
self.bounced.x = true
end
if (ny < 0 and vy > 0) or (ny > 0 and vy < 0) then
vy = -vy * bounciness
self.bounced.y = true
end
self.vx, self.vy = vx, vy
end
function Entity:resolveCollision(col)
self:changeVelocityByCollisionNormal(col.normal.x, col.normal.y)
if col.normal.y == -1 then
if not self.isMini and not self.isPlayer and not self.isDebris then
self.gravity = 0
self.vy = 0
self.onGround = true
end
else
self.onGround = false
end
self:changeVelocityByImpulse(col)
end
function Entity:move(x,y)
local actualX, actualY, collisions, len = self.world:move(self,x,y,
self.checkCollision)
local col
for e = 1, len do
col = collisions[e]
self:resolveCollision(col)
end
self.x, self.y = actualX, actualY
end
function Entity:update(dt)
local vx, vy = self.x+self.vx*dt,self.y+self.vy*dt
self:move(vx,vy,dt)
end
Re: Avoiding moving objects going into walls in bump.lua
Posted: Wed Mar 10, 2021 9:08 am
by MrFariator
You haven't provided what filter(s) you are using (the function self.checkCollision points to), but as far as I can tell what your code is basically saying is that if there are two objects colliding, the one with higher velocity will push the other, by applying its velocity (or impulse) to it. I see nothing about handling tile collisions (technically you check for the presence of a floor by checking that collision normal is -1, but nothing about walls or ceilings), so I can only assume that once this velocity is applied, the object will continue to move with it.
For completeness' sake, please post your filter(s) as well.
Re: Avoiding moving objects going into walls in bump.lua
Posted: Wed Mar 10, 2021 10:27 am
by Gunroar:Cannon()
MrFariator wrote: ↑Wed Mar 10, 2021 9:08 am
You haven't provided what filter(s) you are using (the function self.checkCollision points to), but as far as I can tell what your code is basically saying is that if there are two objects colliding, the one with higher velocity will push the other, by applying its velocity (or impulse) to it. I see nothing about handling tile collisions (technically you check for the presence of a floor by checking that collision normal is -1, but nothing about walls or ceilings), so I can only assume that once this velocity is applied, the object will continue to move with it.
For completeness' sake, please post your filter(s) as well.
Oh, sorry. I didn't think it was important (my fault). And I don't think checking whether it's on a floor is important because the way I use it is topdown so I don't use that variable(just a carry over from last project).
Could it be caused by another object pushing one object through a wall due to a higher velocity? But I change its velocity so the movement is handled by bump. Anything I'm missing?
Here's the filter:
Code: Select all
function Entity:checkCollision(other)
if not other.isBackground then--any thing solid, including walls
return "slide"
end
end
Re: Avoiding moving objects going into walls in bump.lua
Posted: Fri Mar 12, 2021 3:55 pm
by Gunroar:Cannon()
Wait...
pgimeno wrote: ↑Mon Mar 08, 2021 7:07 pm
I don't think bump can push objects in the first place, so the problem is probably on your side.
But the images in bump's wiki imply they do, am I missing something?
and could me changing the velocity affect the movement?