[Solved]Platformer movement with [Bump]

General discussion about LÖVE, Lua, game development, puns, and unicorns.
LXDominik
Prole
Posts: 26
Joined: Wed Oct 01, 2014 9:05 am

Re: [Solved]Platformer movement with [Bump]

Post by LXDominik » Thu Oct 02, 2014 5:04 pm

Thank u for filter ^_^
Attachments
test.love
(43.37 KiB) Downloaded 73 times

User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [Solved]Platformer movement with [Bump]

Post by kikito » Fri Oct 03, 2014 6:56 am

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.
Attachments
test-kikito.love
(55.3 KiB) Downloaded 111 times
When I write def I mean function.

LXDominik
Prole
Posts: 26
Joined: Wed Oct 01, 2014 9:05 am

Re: [Solved]Platformer movement with [Bump]

Post by LXDominik » Fri Oct 03, 2014 7:38 am

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.
Hi, the way u did it player moves alot smoother, thanks for your time~~!
But that bug still exists.
Attachments
bug.png
bug.png (21.02 KiB) Viewed 3069 times

User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [Solved]Platformer movement with [Bump]

Post by kikito » Fri Oct 03, 2014 7:47 am

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 :/
When I write def I mean function.

LXDominik
Prole
Posts: 26
Joined: Wed Oct 01, 2014 9:05 am

Re: [Solved]Platformer movement with [Bump]

Post by LXDominik » Fri Oct 03, 2014 7:49 am

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 :/
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.

Edit : I fixed it~! Insted of creating block per tile, now i create block per object over groups of tiles :
Attachments
Bug fixed.png
Bug fixed.png (6.63 KiB) Viewed 3066 times

User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [Solved]Platformer movement with [Bump]

Post by kikito » Fri Oct 03, 2014 8:16 am

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.
When I write def I mean function.

LXDominik
Prole
Posts: 26
Joined: Wed Oct 01, 2014 9:05 am

Re: [Solved]Platformer movement with [Bump]

Post by LXDominik » Fri Oct 03, 2014 8:21 am

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.
Iam sorry~! Can i help u providing info about my pc or anything?
Also the way i fixed it, now i got less collideble objects on the map, thats good isnt it?
And how to destroy "item" the player collided with? I tried like this and got error ;P

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

User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [Solved]Platformer movement with [Bump]

Post by kikito » Fri Oct 03, 2014 9:42 am

I don't think knowing your pc specs would help, but thanks.
Also the way i fixed it, now i got less collideble objects on the map, thats good isnt it?
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.

Code: Select all

And how to destroy "item" the player collided with? I tried like this and got error ;P
For future reference: any time you get "an error" you should write down exactly what error you get; otherwise it makes it more difficult to help you.

In addition to telling the world that you have removed the enemy, you also need to remove the enemy from your "game list" (the place where you store the enemies). That's all I can think of by looking at that code.

LXDominik
Prole
Posts: 26
Joined: Wed Oct 01, 2014 9:05 am

Re: [Solved]Platformer movement with [Bump]

Post by LXDominik » Fri Oct 03, 2014 10:07 am

At first i create enemy :

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
enemy_create just fills the table

Code: Select all

enemies = {}
function enemy_create(x, y, width, height)
	table.insert(enemies, {x=x,y=y,w = width, h = height})
end
Then i check collision :

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
And got error : bump.lua:298: Item nil must be added to the world before getting its rect. Use world:add(item, l,t,w,h) to add it first.

User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: [Solved]Platformer movement with [Bump]

Post by kikito » Fri Oct 03, 2014 9:24 pm

Hi there,

The error you are having happens because the "item" inside the filter function does not "survive" after the function is executed. You can't use it to remove it. Also, you forgot to include the kind on the enemies.

Here's what I would do:

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

Using the enemies as keys instead of as values in the enemies table is simpler because removing them can be done more easily (otherwise you would need to iterate over the enemies table with a loop every time you wanted to remove an enemy).

Regards!
When I write def I mean function.

Post Reply

Who is online

Users browsing this forum: 4vZEROv and 50 guests