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?
Avoiding moving objects going into walls in bump.lua
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Gunroar:Cannon()
- Party member
- Posts: 1143
- Joined: Thu Dec 10, 2020 1:57 am
Re: Avoiding moving objects going into walls in bump.lua
Is bump.lua your own file?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?
Re: Avoiding moving objects going into walls in bump.lua
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.
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.
- Gunroar:Cannon()
- Party member
- Posts: 1143
- Joined: Thu Dec 10, 2020 1:57 am
Re: Avoiding moving objects going into walls in bump.lua
Thnx for replies...
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?
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()?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.
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
I don't think bump can push objects in the first place, so the problem is probably on your side.
-
- Party member
- Posts: 559
- Joined: Wed Oct 05, 2016 11:53 am
Re: Avoiding moving objects going into walls in bump.lua
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.
"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.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?
- Gunroar:Cannon()
- Party member
- Posts: 1143
- Joined: Thu Dec 10, 2020 1:57 am
Re: Avoiding moving objects going into walls in bump.lua
Thnx for all replies...
Here's the part or the code that moves the entity:
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.
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
-
- Party member
- Posts: 559
- Joined: Wed Oct 05, 2016 11:53 am
Re: Avoiding moving objects going into walls in bump.lua
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.
For completeness' sake, please post your filter(s) as well.
- Gunroar:Cannon()
- Party member
- Posts: 1143
- Joined: Thu Dec 10, 2020 1:57 am
Re: Avoiding moving objects going into walls in bump.lua
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).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.
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
- Gunroar:Cannon()
- Party member
- Posts: 1143
- Joined: Thu Dec 10, 2020 1:57 am
Re: Avoiding moving objects going into walls in bump.lua
Wait...
and could me changing the velocity affect the movement?
But the images in bump's wiki imply they do, am I missing something?
and could me changing the velocity affect the movement?
Last edited by Gunroar:Cannon() on Sat Mar 13, 2021 4:19 pm, edited 1 time in total.
Who is online
Users browsing this forum: No registered users and 4 guests