For my enemy bullet collision-detection, I have multiple functions - within the main enemy fire function - checking whether or not the event.other.class is a bullet, PlayerTank, EnemyTank, PTmine, etc…
Here is what happens when I run the simulator –
If I collide with an enemy’s radar and the enemy begins firing at me, it works fines until I shoot one of the enemy tanks…
Now the enemy bullets are getting removed once they clear the radial sensor or once the collision with an IGmine ends.
I believe the issue comes from this statement
[lua]
local onEnemybulletCollision = function( self, event )
if event.phase == “began” then
EBcollisions = EBcollisions + 1
[/lua]
after that statement, then it goes on to check if it collided with an object that has a class I mentioned above.
towards the end of the function I have this statement:
[lua]
elseif event.phase == “ended”
then
display.remove(self)
EBcollisions = 0
print(" Projectile Removed. EBcollisions set to 0 ")
end
[/lua]
I can’t use a collision filter because if I try to specify what objects the bullet can collide with, it doesn’t work seeing as how all the walls, rocks and other barriers are created&generated via LevelHelper and therefore have no identifier.
I thought using a counter for keeping track of how many collisions have occurred would work, but since a collision is technically occurring when it hits the radar or an IGmine (which up until I shoot at something, the IGmine doesn’t collide with the bullets via my RGCC) it ups the collision-count +1 which then causes the bullet to remove itself once the collision with the radar or IGmine has ended.
I am having the same issue with my user-bullet collision and like with the enemy-bullet, I have PBcollisions being increased&decreased on the began and ended phase of the collision.
** Again, nothing weird happens until I shoot an enemy tank…? As if that is what 'kicks in the physics engine **
P.S. Obviously since I have display.remove(self) being called on the ended phase, the EBcollisions count would become void. I think the reason I have a counter for the bullet is because at one time I had an if statement that would remove the bullet if EBcollisions = 2 - just to clarify.