Avoiding moving objects going into walls in bump.lua

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Gunroar:Cannon()
Party member
Posts: 1143
Joined: Thu Dec 10, 2020 1:57 am

Avoiding moving objects going into walls in bump.lua

Post 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?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
darkfrei
Party member
Posts: 1204
Joined: Sat Feb 08, 2020 11:09 pm

Re: Avoiding moving objects going into walls in bump.lua

Post 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?
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
eliddell
Prole
Posts: 20
Joined: Sat Dec 10, 2016 6:38 pm

Re: Avoiding moving objects going into walls in bump.lua

Post 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.
User avatar
Gunroar:Cannon()
Party member
Posts: 1143
Joined: Thu Dec 10, 2020 1:57 am

Re: Avoiding moving objects going into walls in bump.lua

Post 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?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: Avoiding moving objects going into walls in bump.lua

Post by pgimeno »

I don't think bump can push objects in the first place, so the problem is probably on your side.
MrFariator
Party member
Posts: 559
Joined: Wed Oct 05, 2016 11:53 am

Re: Avoiding moving objects going into walls in bump.lua

Post 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.
User avatar
Gunroar:Cannon()
Party member
Posts: 1143
Joined: Thu Dec 10, 2020 1:57 am

Re: Avoiding moving objects going into walls in bump.lua

Post 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
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
MrFariator
Party member
Posts: 559
Joined: Wed Oct 05, 2016 11:53 am

Re: Avoiding moving objects going into walls in bump.lua

Post 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.
User avatar
Gunroar:Cannon()
Party member
Posts: 1143
Joined: Thu Dec 10, 2020 1:57 am

Re: Avoiding moving objects going into walls in bump.lua

Post 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
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
Gunroar:Cannon()
Party member
Posts: 1143
Joined: Thu Dec 10, 2020 1:57 am

Re: Avoiding moving objects going into walls in bump.lua

Post 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?
Image
Image
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.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests