[library] bump.lua v3.1.4 - Collision Detection

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by kikito »

megalukes wrote:I was struggling with collisions for a while (using HC and programming my own module), but this lib saved me from a lot of trouble I was going through. Thank you very much. :awesome:
Thanks, I'm glad it worked well for you!
When I write def I mean function.
User avatar
megalukes
Citizen
Posts: 94
Joined: Fri Jun 27, 2014 11:29 pm
Location: Brazil

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by megalukes »

Is there a way I can edit the rectangle's position inside the world?
For instance, I need the bounding box to be 6 pixels to the right and down to make it work with my graphic, so I did this:

Code: Select all

world:update(player, player.x+6, player.y+6)
However, this seems to bug my collision detection. It acts as if the rect was still in player.x, player.y. Is there a better way to do that? I didn't want to change the graphic because I use a different collision system for the tilemap, so I'm stuck.

EDIT: I found a way to do it. I thought I should use :update somewhere else with adjustment coords, so I tried to add them in the :move call.

Code: Select all

local goalX = player.x + player.addX
local goalY = player.y + player.addY
local actualX, actualY, cols, len = world:move(player, goalX, goalY, playerFilter)
player.x, player.y = actualX - player.addX, actualY - player.addY
User avatar
NightKawata
Party member
Posts: 294
Joined: Tue Jan 01, 2013 9:18 pm
Location: Cyberspace, Room 6502
Contact:

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by NightKawata »

megalukes wrote:Is there a way I can edit the rectangle's position inside the world?
For instance, I need the bounding box to be 6 pixels to the right and down to make it work with my graphic, so I did this:

Code: Select all

world:update(player, player.x+6, player.y+6)
However, this seems to bug my collision detection. It acts as if the rect was still in player.x, player.y. Is there a better way to do that? I didn't want to change the graphic because I use a different collision system for the tilemap, so I'm stuck.

EDIT: I found a way to do it. I thought I should use :update somewhere else with adjustment coords, so I tried to add them in the :move call.

Code: Select all

local goalX = player.x + player.addX
local goalY = player.y + player.addY
local actualX, actualY, cols, len = world:move(player, goalX, goalY, playerFilter)
player.x, player.y = actualX - player.addX, actualY - player.addY
For things like that, I tend to not mess with the physics box itself, rather I draw the sprite with an offset in a :draw function. Usually you'll define an offset when the object is initialized, and subtract that from the rendering function itself.
"I view Python for game usage about the same as going fishing with a stick of dynamite. It will do the job but it's big, noisy, you'll probably get soaking wet and you've still got to get the damn fish out of the water." -taylor
User avatar
alberto_lara
Party member
Posts: 372
Joined: Wed Oct 30, 2013 8:59 pm

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by alberto_lara »

I have an issue (maybe it has a workaround, if so, please let me know), I created a simple grid of blocks and, when I slide through the "tunnels", the player gets stuck sometimes, it's colliding with the corners of some blocks, any ideas? Here's an image showing what I mean:

Image

The strange thing is, it slides well with the squares on the left, but not so with the right ones (I'm sure the blocks have the same position vertically, and horizontally, they're generated with a double for, this seems to happen only when "touching" the left side of any red square actually).

Any ideas? Thanks in advance, sorry for the bad English.

here's the .love:
bump.lua-simpledemo.love
(10.35 KiB) Downloaded 246 times
Last edited by alberto_lara on Sun Jul 02, 2017 5:05 pm, edited 1 time in total.
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by zorg »

alberto_lara wrote: Sun Jul 02, 2017 12:21 am I have an issue...
-snip-
Any ideas?
Maybe provide your code? based on how blurry those lines are i want to think you're doing something floaty there that you shouldn't...
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
alberto_lara
Party member
Posts: 372
Joined: Wed Oct 30, 2013 8:59 pm

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by alberto_lara »

I actually forgot to add the .love file, sorry about that (post edited). The weird lines are because I'm using a stretched canvas with nearest filtering, but the squares are correctly aligned.

EDIT: Here's an updated .love, I'm printing the coords of the square so you can see they're correctly aligned:
bump.lua-simpledemo.love
(16.96 KiB) Downloaded 250 times
EDIT2: I fixed it by setting the width and height of the player as integer numbers, it's still weird for me the previous behavior though, here's the fixed .love:
bump_demo.love
(16.96 KiB) Downloaded 256 times
MrFariator
Party member
Posts: 559
Joined: Wed Oct 05, 2016 11:53 am

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by MrFariator »

I had a similar problem with my game (player would get stuck when walking from one tile to the next because gravity would interrupt the movement), and the fix was to step movement in two different calls to bumpWorld:move(). In my case because my game is a 2d platformer, I first step the character on the x axis, and then on the y axis.
User avatar
fairenough
Prole
Posts: 12
Joined: Fri Aug 11, 2017 4:44 pm
Contact:

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by fairenough »

Hi all!

I'm brand new to Lua, Love2D, and bump, and have what may be a very dumb question.

I followed this tutorial (the parts that are posted anyway), and everything was going smoothly, but then I went off and tried to build on what I'd learned, and now I'm running into a stumbling block.

Basically I've got a little cube dude that you can move around a couple platforms and jump. That's it. This worked great for platforms (ground), but as soon as I tried to make walls, it didn't work right anymore. Basically when you sidle up against a wall and then try to jump, the player just sort of jitters up and down.

Here's the code for the Ground class (using hump for that):

Code: Select all

local Class = require 'libs.hump.class'
local Entity = require 'entities.Entity'

local Ground = Class{
  __includes = Entity -- Ground class inherits our Entity class
}

function Ground:init(world, x, y, w, h)
  Entity.init(self, world, x, y, w, h)

  self.world:add(self, self:getRect())
  self.isGround = true
end

function Ground:draw()
  love.graphics.rectangle('fill', self:getRect())
end

return Ground

Here's the code for the stage, where it creates a bunch of grounds (and a player) and adds them to the world:

Code: Select all

function gameLevel1:enter()
  -- Game Levels do need collisions.
  world = bump.newWorld(16) -- Create a world for bump to function in.

  -- Initialize our Entity System
  Entities:enter()
  player = Player(world, 100, 50)
  ground_0 = Ground(world, 200, love.graphics.getHeight()-250, 640, 50)
  ground_1 = Ground(world, 0, love.graphics.getHeight()-50, love.graphics.getWidth(), 50)
  ground_2 = Ground(world, 400, 150, 640, 50)
  wall_0 = Ground(world, 0,0,50,love.graphics.getHeight())
  wall_1 = Ground(world, love.graphics.getWidth()-50 ,0,50,love.graphics.getHeight())

  -- Add instances of our entities to the Entity List
  Entities:addMany({player, ground_0, ground_1, wall_0, ground_2, wall_1})

  -- Camera?
  -- camera = Camera(player)
end
and here's the code for jumping, and checking for collisions, which is in the update function of my player:

Code: Select all

  if love.keyboard.isDown("up", "w") then
    if -self.yVelocity < self.jumpMaxSpeed and not self.hasReachedMax then
      self.yVelocity = self.yVelocity - self.jumpAcc * dt
    elseif math.abs(self.yVelocity) > self.jumpMaxSpeed then
      self.hasReachedMax = true
    end

    self.isGrounded = false -- we are no longer in contact with the ground
  end

  -- these store the location the player should arrive at
  local goalX = self.x + self.xVelocity
  local goalY = self.y + self.yVelocity

  -- Move the player while testing for collisions
  self.x, self.y, collisions, len = self.world:move(self, goalX, goalY)
and then this is in the player's draw:

Code: Select all

function player:draw()
  love.graphics.draw(self.img, self.x, self.y)
  self.rc:draw(self.x, self.y)
end
I can provide any more information you need, and am excited to dig in and sort this out! Thanks!
User avatar
Nuthen224
Citizen
Posts: 50
Joined: Sun Jul 28, 2013 9:40 pm

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by Nuthen224 »

Hi fairenough. I have used bump for a few projects. I looked over your code snippets and no issues stood out to me. Could you post a .love so I could take a closer look at the issue?
g0r1ll4
Prole
Posts: 5
Joined: Mon Aug 07, 2017 3:59 am

Re: [library] bump.lua v3.1.4 - Collision Detection

Post by g0r1ll4 »

Hi, I've got a question too :

In what case is the "bounce" filter usefull ? Maybe I use it wrong but the bounce is only applied for 1 frame, I don't see any difference between using it and "slide" .
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests