Help with projectiles and bump library?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 1
- Joined: Fri Sep 28, 2018 11:32 pm
Help with projectiles and bump library?
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?
-
- Party member
- Posts: 548
- Joined: Wed Oct 05, 2016 11:53 am
Re: Help with projectiles and bump library?
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:
Now, we just need to define a filter with which to detect a player, or other collidable object:
Now, when you update the projectile in the bump world, loop through the collisions:
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.
Code: Select all
local projectileProperties = {
isSolid = false,
isDamaging = true,
damage = {
amount = 2,
pushback = 2
}
}
--insert the object into the bump world
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
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
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests