Page 1 of 1

[Bump Physics] How to use this?

Posted: Thu Sep 19, 2019 12:18 pm
by ilovelove2019
Hello everyone! I'm making a game and I am using Bump library. When reading the tutorial, I think it is suitable for me. But I get this small problem, and I think it's easy with pro like you.
This is some code in tutorial:

Code: Select all

function movePlayer(player, dt)
  local goalX, goalY = player.vx * dt, player.vy * dt
  local actualX, actualY, cols, len = world:move(player, goalX, goalY, playerFilter)
  player.x, player.y = actualX, actualY
  for i=1,len do
    local other = cols[i].other
    if other.isCoin then
      takeCoin(other)
    elseif other.isExit then
      changeLevel()
    elseif other.isSpring then
      highJump()
    end
  end
end
I don't know how to use this: other.isCoin, other.isExit, other.isSpring. How to identify it? We need to make that function? Or we needn't?
Or it have some method to know it is coin or exit,... in the tutorial but I miss it? Let you check it out: https://github.com/kikito/bump.lua . Help me please! Thank you so much. Hope you will help me soon soon! I am so excited to make a game with bump as soon as possible. Sorry because my English is not good. My bad. My bad.

Re: [Bump Physics] How to use this?

Posted: Thu Sep 19, 2019 1:40 pm
by raidho36
The "other.isCoin" etc. is simply a flag defined in the table, set to true or false. The "other" is set to whichever other table (object) is in collision with current object.

So you have some object that's a coin, and it has "self.isCoin = true" in it. Same for an object that's an exit and an object that's a spring.

The "cols" table comes from elsewhere and I assume it contains list of collisions between player object and everything else.

Re: [Bump Physics] How to use this?

Posted: Thu Sep 19, 2019 2:03 pm
by joedono
The "other" object is whatever object/table you added to bump when you created the objects in the world. You can assume it'll be whatever you added.

My approach is that any object I add to Bump has a "type" that's a simple string. I'm really consistent about this, so I know that anything I can collide with has this "type" property. I check that instead of "isCoin" or "isExit" and act on the collisions based on that instead.

Re: [Bump Physics] How to use this?

Posted: Thu Sep 19, 2019 2:29 pm
by ilovelove2019
raidho36 wrote: Thu Sep 19, 2019 1:40 pm The "other.isCoin" etc. is simply a flag defined in the table, set to true or false. The "other" is set to whichever other table (object) is in collision with current object.

So you have some object that's a coin, and it has "self.isCoin = true" in it. Same for an object that's an exit and an object that's a spring.

The "cols" table comes from elsewhere and I assume it contains list of collisions between player object and everything else.
Oh! I understand it now! Thanks you so much. It is a smart way. "self.isCoin"! Thank you so much!

Re: [Bump Physics] How to use this?

Posted: Thu Sep 19, 2019 2:31 pm
by ilovelove2019
joedono wrote: Thu Sep 19, 2019 2:03 pm The "other" object is whatever object/table you added to bump when you created the objects in the world. You can assume it'll be whatever you added.

My approach is that any object I add to Bump has a "type" that's a simple string. I'm really consistent about this, so I know that anything I can collide with has this "type" property. I check that instead of "isCoin" or "isExit" and act on the collisions based on that instead.
Thank for your advice. It is a good way too. But I think it not suitable for a noob like me :) LOL. Thank you so much.

Re: [Bump Physics] How to use this?

Posted: Thu Sep 19, 2019 2:32 pm
by ilovelove2019
Problem Solved.