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!!
A bump.lua question
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 17
- Joined: Sun Apr 14, 2019 5:14 pm
Re: A bump.lua question
If you don't want your character to collide with the button maybe just don't add it with world:add ?
-
- Party member
- Posts: 548
- Joined: Wed Oct 05, 2016 11:53 am
Re: A bump.lua question
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:
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:
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:
After that you'll just have to figure out how to handle the collision response when the player touches the button.
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
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
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 )
Re: A bump.lua question
Ooh, that's works!!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: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.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
So in your case, when you want to move your character, it could be something like this: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 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
After that you'll just have to figure out how to handle the collision response when the player touches the button.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 )
Thanks for the help!!!
Last edited by uSources on Mon Apr 15, 2019 5:15 pm, edited 1 time in total.
Re: A bump.lua question
As I have already put in the post, I need to register the collisionmaxtrautwein 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 ?
But thanks for the response
Who is online
Users browsing this forum: Google [Bot] and 1 guest