Thanks, I'm glad it worked well for you!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.
[library] bump.lua v3.1.4 - Collision Detection
- 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
When I write def I mean function.
Re: [library] bump.lua v3.1.4 - Collision Detection
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:
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.
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)
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
- 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
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.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:
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.Code: Select all
world:update(player, player.x+6, player.y+6)
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
"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
- alberto_lara
- Party member
- Posts: 372
- Joined: Wed Oct 30, 2013 8:59 pm
Re: [library] bump.lua v3.1.4 - Collision Detection
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:
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:
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:
Last edited by alberto_lara on Sun Jul 02, 2017 5:05 pm, edited 1 time in total.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: [library] bump.lua v3.1.4 - Collision Detection
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 True 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.
- alberto_lara
- Party member
- Posts: 372
- Joined: Wed Oct 30, 2013 8:59 pm
Re: [library] bump.lua v3.1.4 - Collision Detection
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: 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:
EDIT: Here's an updated .love, I'm printing the coords of the square so you can see they're correctly aligned: 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:
-
- Party member
- Posts: 548
- Joined: Wed Oct 05, 2016 11:53 am
Re: [library] bump.lua v3.1.4 - Collision Detection
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.
- fairenough
- Prole
- Posts: 12
- Joined: Fri Aug 11, 2017 4:44 pm
- Contact:
Re: [library] bump.lua v3.1.4 - Collision Detection
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):
Here's the code for the stage, where it creates a bunch of grounds (and a player) and adds them to the world:
and here's the code for jumping, and checking for collisions, which is in the update function of my player:
and then this is in the player's draw:
I can provide any more information you need, and am excited to dig in and sort this out! Thanks!
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
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)
Code: Select all
function player:draw()
love.graphics.draw(self.img, self.x, self.y)
self.rc:draw(self.x, self.y)
end
Re: [library] bump.lua v3.1.4 - Collision Detection
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
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" .
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" .
Who is online
Users browsing this forum: Google [Bot] and 0 guests