Page 1 of 1

Help with projectiles and bump library?

Posted: Sun Sep 30, 2018 11:20 pm
by NubianRice
So I'm trying to make the player shoot out a projectile but the problem is, I don't know how I would use the bump library to see what the projectile is touching. I want to make it so that if it touches a player it would make them take damage. Can someone help me?

Re: Help with projectiles and bump library?

Posted: Mon Oct 01, 2018 10:05 pm
by MrFariator
When you insert objects into the bump world, you can use just about anything: a string, number, or table. If you use a table to define the bump world objects, you can define them along the lines of:

Code: Select all

local projectileProperties = {
  isSolid    = false,
  isDamaging = true,
  damage     = {
    amount    = 2,
    pushback  = 2
  }
}
--insert the object into the bump world 
Now, we just need to define a filter with which to detect a player, or other collidable object:

Code: Select all

local projectileFilter = function(item, other)
  if     other.isPlayer   then return 'touch'
  elseif other.isWall   then return 'bounce'
  -- other possible cases
  end
end
Now, when you update the projectile in the bump world, loop through the collisions:

Code: Select all

local actualX, actualY, collisions, numberOfCollisions = world:move(projectileInstance, targetX, targetY, projectileFilter) 
for i = 1, numberOfCollisions do
  -- the 'other' in collisions table entries returns the object that you use for adding objects into the bump world
  if collisions[i].other.isPlayer then
      -- deal damage to the player here
  end
  -- handle other collisions (eq. walls)
end
Because bump allows you to set up your objects in any number of ways you can pick whatever approach you wish. For instance, you could just store the player object itself in the bump world, or just a string id and use a lookup table in the collision resolution phase, or whatever you're comfortable with.