Page 21 of 23

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

Posted: Wed Nov 23, 2016 7:14 pm
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!

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

Posted: Thu Nov 24, 2016 12:13 am
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

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

Posted: Thu Nov 24, 2016 5:52 am
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.

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

Posted: Sun Jul 02, 2017 12:21 am
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

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

Posted: Sun Jul 02, 2017 3:48 am
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...

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

Posted: Sun Jul 02, 2017 5:03 pm
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

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

Posted: Mon Jul 03, 2017 5:02 pm
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.

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

Posted: Fri Aug 11, 2017 5:46 pm
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!

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

Posted: Sat Aug 12, 2017 1:25 am
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?

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

Posted: Sun Aug 13, 2017 11:12 am
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" .