Game Development Community

bullet collision question

by Jeff Brown · in Torque Game Builder · 05/15/2009 (1:26 am) · 7 replies

I have an object shooting a bullet and when it collides with the enemy it goes straight to the next enemy (kind of like a chain lightning spell). The bullet causes 1 damage when it collides with the enemy but it doesn't get safe deleted on collision because it needs to 'bounce' to the next target so it causes 1 damage to each enemy many times a second because of the onCollision call it uses. I want it to do just 1 damage to each enemy it hits. How would I go about receiving the collision just once between the objects?
I thought about safe deleting the bullet on collision, then making another at that location and shooting towards the next target, but I want to see some opinions on where I should go before I try anything.

#1
05/15/2009 (11:02 am)
I don't know if this is the best solution, but I would probably store the bullet in a SimSet inside the object that it collided with. Then when that object receives collision notifications, it just checks to see if the bullet that it is colliding with is in the SimSet, if it is, then it ignores the collision, if not then it takes damage and adds the bullet to the SimSet.

Then when the bullet is eventually deleted, it will automatically be removed from the SimSet, so you don't have to worry about cleaning out old bullets from the lists.
#2
05/15/2009 (11:57 am)
I don't want it to ignore the collision because I want it to do damage to every enemy that it touches. Theoretically I want the collision callback to be called just once per object it hits, and onCollision is called as long as the bullet is touching an object.
#3
05/16/2009 (12:55 am)
Is setMaxIterations() still broke?
#4
05/19/2009 (1:42 am)
onCollision will get called every frame that the bullet is colliding, you can't change that unless you turn off collision. So all you need to do is use Darius' technique to avoid adding more damage to an enemy if it has already collided with this bullet.
#5
05/19/2009 (6:07 am)
Have you considered moving the bullet to the other side of the enemy after the collision on the vector to the next enemy?
#6
05/19/2009 (9:37 am)
Sorry, I guess I didn't describe what I meant very well.

Here's a description of what would happen:

Bullet1 collides with Enemy1

Enemy1's collision callback gets called. Enemy1 checks its bullet list for Bullet1. It doesn't find it, so it takes damage, and adds Bullet1 to its bullet list.

Bullet1 collides with Enemy1 again

Enemy1's collision callback gets called. Enemy1 checks its bullet list for Bullet1. Bullet1 is there, so it doesn't take damage.

Bullet1 collides with Enemy2

Enemy2's collision callback gets called. Enemy2 checks its bullet list for Bullet1. It doesn't find it, so it takes damage, and adds Bullet1 to its bullet list.

Bullet2 collides with Enemy1

Enemy1's collision callback gets called. Enemy1 checks its bullet list for Bullet2. It doesn't find it, so it takes damage, and adds Bullet2 to its bullet list.

Bullet1 collides with Enemy2 again

Enemy2's collision callback gets called. Enemy2 checks its bullet list for Bullet1. Bullet1 is there, so it doesn't take damage.

And so on.

Each bullet does damage to each enemy exactly once.

I hope that makes more sense.
#7
05/19/2009 (4:10 pm)
That makes perfect sense, thanks.