A bump.lua question

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.
Post Reply
uSources
Prole
Posts: 4
Joined: Sun Apr 14, 2019 5:42 pm

A bump.lua question

Post by uSources »

Hi everyone!

I recently started studying Love2D, to create small personal projects.

For the physics library I used the kikito´s library called bump.lua

I have created a small stage which has a character, a wall and a button.

I would like to make the character collide with the wall. But pass over the button, registering that player goes over him.

I do not know if it's possible to do this with this library

Thank you!! :awesome: :awesome:
maxtrautwein
Prole
Posts: 17
Joined: Sun Apr 14, 2019 5:14 pm

Re: A bump.lua question

Post by maxtrautwein »

If you don't want your character to collide with the button maybe just don't add it with world:add ?
MrFariator
Party member
Posts: 548
Joined: Wed Oct 05, 2016 11:53 am

Re: A bump.lua question

Post by MrFariator »

You need to define a filter for your character and use it in conjuction with world:move().

Consider the example filter from the github page:

Code: Select all

local playerFilter = function(item, other)
  if     other.isCoin   then return 'cross'
  elseif other.isWall   then return 'slide'
  elseif other.isExit   then return 'touch'
  elseif other.isSpring then return 'bounce'
  end
  -- else return nil
end

-- an example on how to use said filter
function movePlayer(player, dt)
  local goalX, goalY = player.vx * dt, player.vy * dt
  local actualX, actualY, cols, len = world:move(player, goalX, goalY, playerFilter)
  player.x, player.y = actualX, actualY
  for i=1,len do
    local other = cols[i].other
    if other.isCoin then
      takeCoin(other)
    elseif other.isExit then
      changeLevel()
    elseif other.isSpring then
      highJump()
    end
  end
end
What this filter does is that the moved object will go right through coins (but still register the collision), slide along the surfaces of walls, stop moving as it touches an exit, and bounces off when hitting a spring. For any other objects, the collisions are ignored.

So in your case, when you want to move your character, it could be something like this:

Code: Select all

local characterFilter = function(item, other)
  if     other.isButton then return 'cross'
  elseif other.isWall then return 'slide'
  end
end

-- in character movement code
world:move ( character, destinationX, destinationY, characterFilter ) -- pass the filter to world:move 
The important part to remember is that the table you are using for the button needs to contain the field "isButton", and it needs to be a non-false and non-nil value. Like for example:

Code: Select all

local buttonObj = {isButton = true, x = 10, y = 10, w = 20, h = 5}
world:add ( buttonObj, buttonObj.x, buttonObj.y, buttonObj.w, buttonObj.h )
After that you'll just have to figure out how to handle the collision response when the player touches the button.
uSources
Prole
Posts: 4
Joined: Sun Apr 14, 2019 5:42 pm

Re: A bump.lua question

Post by uSources »

MrFariator wrote: Mon Apr 15, 2019 1:02 pm You need to define a filter for your character and use it in conjuction with world:move().

Consider the example filter from the github page:

Code: Select all

local playerFilter = function(item, other)
  if     other.isCoin   then return 'cross'
  elseif other.isWall   then return 'slide'
  elseif other.isExit   then return 'touch'
  elseif other.isSpring then return 'bounce'
  end
  -- else return nil
end

-- an example on how to use said filter
function movePlayer(player, dt)
  local goalX, goalY = player.vx * dt, player.vy * dt
  local actualX, actualY, cols, len = world:move(player, goalX, goalY, playerFilter)
  player.x, player.y = actualX, actualY
  for i=1,len do
    local other = cols[i].other
    if other.isCoin then
      takeCoin(other)
    elseif other.isExit then
      changeLevel()
    elseif other.isSpring then
      highJump()
    end
  end
end
What this filter does is that the moved object will go right through coins (but still register the collision), slide along the surfaces of walls, stop moving as it touches an exit, and bounces off when hitting a spring. For any other objects, the collisions are ignored.

So in your case, when you want to move your character, it could be something like this:

Code: Select all

local characterFilter = function(item, other)
  if     other.isButton then return 'cross'
  elseif other.isWall then return 'slide'
  end
end

-- in character movement code
world:move ( character, destinationX, destinationY, characterFilter ) -- pass the filter to world:move 
The important part to remember is that the table you are using for the button needs to contain the field "isButton", and it needs to be a non-false and non-nil value. Like for example:

Code: Select all

local buttonObj = {isButton = true, x = 10, y = 10, w = 20, h = 5}
world:add ( buttonObj, buttonObj.x, buttonObj.y, buttonObj.w, buttonObj.h )
After that you'll just have to figure out how to handle the collision response when the player touches the button.
Ooh, that's works!!

Thanks for the help!!! :awesome: :awesome:
Last edited by uSources on Mon Apr 15, 2019 5:15 pm, edited 1 time in total.
uSources
Prole
Posts: 4
Joined: Sun Apr 14, 2019 5:42 pm

Re: A bump.lua question

Post by uSources »

maxtrautwein wrote: Mon Apr 15, 2019 10:18 am If you don't want your character to collide with the button maybe just don't add it with world:add ?
As I have already put in the post, I need to register the collision

But thanks for the response :awesome:
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests