Re: [Solved]Platformer movement with [Bump]
Posted: Thu Oct 02, 2014 5:04 pm
Thank u for filter ^_^
Hi, the way u did it player moves alot smoother, thanks for your time~~!kikito wrote:Hi LXDominik,
I tried it several times but could not reproduce the issue you mentioned. You must have found a difficult-to-reproduce thing.
I went through your code and realized that there were some confusion. You were using dx and dy as if they were velocities in some occasions, and as if they were increments in space in others.
I've modified your test code, cleaning up this (now dx and dy always refer to space - velocities always in player.vx and player.vy). I've also used onGround only to do the jumping, so you can see how it is done. The timer was also not needed after I did this. Feel free to use whatever you want from it.
That strange. I have tried to restart .love several times, and some times yes there is no bug, and some times it's there T_T.kikito wrote:Yes, I tried it with both my code and yours, and I was not able to even see the bug.
I jumped, I "hugged the wall", then I fell down, and I was able to walk left and right :/
Iam sorry~! Can i help u providing info about my pc or anything?kikito wrote:Yes, that is one way to fix that, but in bump there is explicit code to handle the "getting stuck in corners" thing. I worked on it for a year :/ . You telling me that it happens in your computer is ... disturbing. It should not.
Code: Select all
if dx ~= 0 or dy ~= 0 then
local future_l, future_t = player.x + dx, player.y + dy
local collideWithEnemy = function(item) return item.kind == 'Enemy' end
local cols, len = world:check(player, future_l, future_t, collideWithEnemy)
if len > 0 then
world:remove(item)
end
end
That's good, yes, but also not possible in all cases. People need to be able to build tile-based things, they are quite useful.Also the way i fixed it, now i got less collideble objects on the map, thats good isnt it?
Code: Select all
And how to destroy "item" the player collided with? I tried like this and got error ;P
Code: Select all
for i,v in ipairs(enemiesLayer.objects) do
enemy_create(v.x, v.y, v.width, v.height)
world:add(enemies[i], v.x,v.y,v.width,v.height)
enemies[i].kind = 'Enemy'
end
Code: Select all
enemies = {}
function enemy_create(x, y, width, height)
table.insert(enemies, {x=x,y=y,w = width, h = height})
end
Code: Select all
local future_l, future_t = player.x + dx, player.y + dy
local collideWithEnemy = function(item) return item.kind == 'Enemy' end
local cols, len = world:check(player, future_l, future_t, collideWithEnemy)
if len > 0 then
table.remove(enemies, item)
world:remove(item)
end
Code: Select all
enemies = {}
-- changed this function to store enemies as keys instead of values in the enemies table (easier to remove later)
-- also, added the missing 'kind' attribute
function enemy_create(x, y, width, height)
local enemy = {x=x,y=y,w = width, h = height, kind = 'Enemy'}
enemies[enemy] = true
end
...
-- You can put this as a local inside the player.lua file; no need to declare it inside the player update loop
local collideWithEnemy = function(item) return item.kind == 'Enemy' end
...
local future_l, future_t = player.x + dx, player.y + dy
local cols, len = world:check(player, future_l, future_t, collideWithEnemy)
if len > 0 then
local enemy = cols[1].other
world:remove(enemy) -- removes enemy from the world
enemies[enemy] = nil -- removes enemy from the list of enemies
end