[Solved]Platformer movement with [Bump]
Re: [Solved]Platformer movement with [Bump]
Thank u for filter ^_^
- Attachments
-
- test.love
- (43.37 KiB) Downloaded 134 times
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: [Solved]Platformer movement with [Bump]
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.
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 187 times
When I write def I mean function.
Re: [Solved]Platformer movement with [Bump]
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.
But that bug still exists.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: [Solved]Platformer movement with [Bump]
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 :/
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.
Re: [Solved]Platformer movement with [Bump]
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 :/
Edit : I fixed it~! Insted of creating block per tile, now i create block per object over groups of tiles :
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: [Solved]Platformer movement with [Bump]
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.
Re: [Solved]Platformer movement with [Bump]
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.
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
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: [Solved]Platformer movement with [Bump]
I don't think knowing your pc specs would help, but thanks.
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.
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
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.
Re: [Solved]Platformer movement with [Bump]
At first i create enemy :
enemy_create just fills the table
Then i check collision :
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.
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
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: [Solved]Platformer movement with [Bump]
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:
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!
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
Regards!
When I write def I mean function.
Who is online
Users browsing this forum: Ahrefs [Bot] and 7 guests