Collision detection - shmup game


I’m working on a little shmup game since several weeks in Blender 2.570, and i have a problem with collisions.

I’m able to shoot bullets with the main ship, and my bullets can kill enemies as well (end object function). The enemies are sensor objects, while bullets are static actors. The sensor realises the collision, and the enemy objects replaces itself with an explosion and the object ends. That’s pretty simple.

But. I can’t end the bullet object, which is always added to the scene with the ‘edit object/add object’ actuator. Is there a way to add sensors to static actors, or am i doing something completely wrong? Thanks for your help in advance!

Why is your bullet static? Is it stading around like a pole to be hit by a ship?

Can’t you set the added objects lifespan? There is a numeric field that allows you to do this in the add object actuator.

They have a livespan currently, else the game would slow down after shooting lots of bullets (it’s meant to be a bullethell game). The only problem is, that i can’t remove the bullets after they collide with the enemy. They simply fly through it. Collision detection works fine however: the enemy dies properly, even explosion starts… but if there’s 2 enemies behind each other, 1 bullet can hit both. And if there’s a bigger enemy with shield: it just gets worse (one bullet causes lots of collision pulses).

They are not standing around, they simply move forward. but if i set the bullets to sensor, the enemy objects cant check for collision. They have to be actors as far as i know: even if i’m not using any physics.

here’s a small example of my problem… hope, it helps to understand my trouble.

I think I can remeber that the collision sensor does not work on static objects. This is because it is assumed static object are … static.
If you use loc to move the bullets around, the teleport and do not move. But this is a different problem.

You might want to make your bullets dynamic or rigid bodies. When starting, you need to apply a force just once instead or you provide a continues LinV.

That should resolve your problem.

great! many thanks! it looks like, the problem is solved now, bullets finally are able to check collisions and die. even replaced the loc with forces, and collision detection went a lot more accurate.

thanks again!

I would recommend making both the bullet and the enemies dynamic ghost types (without gravity, if you so wish). This would enable all objects to detect collisions with each other. As to your problem of one bullet hitting multiple enemies, the problem is that the bullet collides with enemy 1, and is set to be removed from the scene - however, enemy 2 is also colliding with the bullet, and so also takes a hit. You will have to use a little Python to basically make it so that the bullet isn’t a ‘bullet’ anymore by removing the variable that the enemies are looking for when they look for a collision between themselves and a bullet (so that the bullet is rendered inactive on collision with the enemy, before it gets removed from the scene).

The bullet’s script is this:

from bge import logic # Import the bge module's logic module

cont = logic.getCurrentController() # Get the controller running this script
obj = cont.owner # Get the object that the controller belongs to

enemycol = cont.sensors['EnemyCollisionSensorName'] # Get the sensor that the bullet uses to collide with enemies; replace 'EnemyCollisionSensorName' with the name of the enemy collision sensor
if enemycol.positive:
     obj.endObject() # Delete the bullet object itself
     del obj['bullet']   # Delete the 'bullet' variable (or whatever variable that you use to identify the bullet being one)

Put that script in the controller, connected to a collision sensor, and rename the line in the code ‘EnemyCollisionSensorName’ the name of the attached collision sensor.