Question about 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.
Post Reply
User avatar
JacKobOriginal
Prole
Posts: 11
Joined: Thu Mar 22, 2018 12:05 am
Location: Colombia
Contact:

Question about Bump.lua

Post by JacKobOriginal »

Does anyone know how to check for collisions and check for when not colliding with something in bump.lua?

I am making a platformer, and I've had problems with jumping, the player would always be levitating when not on the platform, and I've used the code from this: https://love2d.org/wiki/Tutorial:Baseline_2D_Platformer

Here's the .love file in case: https://drive.google.com/file/d/1jQ9J8M ... sp=sharing
Follow my GameDev Twitter: https://twitter.com/qqnutgames
Play Lil Jingle: https://qqnut.itch.io/lil-jingle
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: Question about Bump.lua

Post by pgimeno »

I don't advise following that tutorial's recommendations regarding checking whether the player can jump. It has caused problems to others in past, like this guy: https://love2d.org/forums/viewtopic.php ... 35#p223735

Check the docs of Bump. It returns the collisions and the collision normals. The collision normals can help determining if your player can jump.
MrFariator
Party member
Posts: 559
Joined: Wed Oct 05, 2016 11:53 am

Re: Question about Bump.lua

Post by MrFariator »

By default, bump.lua will report any and all collisions if you don't provide a filter to its functions.
Here's some crude, quick code example:

Code: Select all

local playerObj   = { isPlayer = true }
local pickup      = { isPickup = true }

-- populate the world
local playerX   = 0
local bumpWorld = bump.newWorld ()
bumpWorld:add ( playerObj,  playerX, 0, 10, 10 )
bumpWorld:add ( pickup,          20, 0,  5,  5 )

-- define filter for player to use
local playerFilter = function ( playerObj, otherObj )
  if otherObj.isPickup then return "cross" else return "slide" end
end

-- move player obj
playerX = playerX + 1
local actualX, actualY, cols, len = bumpWorld:move ( playerObj, playerX, 0, playerFilter )
playerX = actualX -- store the realized x coordinate

-- check collisions
for i = 1, len do
  if cols[i].other.isPickup then
    -- code to handle picking up the object
  else 
    -- do other things
  end
end
The main thing here is the playerFilter function, which will move over objects that are defined as pickups (but register the collision), and slide along the surfaces of other elements. For details on other collision responses (touch, bounce), check the documentation. Another thing worth pointing out that when using the "slide" response, if an object ends up or is spawned inside another, and the slide response is triggered, the object will 'zip' or 'warp' outside it.

Also please note that the objects that you insert to bump world can use just about any kind of structure you desire. As far as I know, they can be strings, numbers or tables.
Post Reply

Who is online

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