Collision with projectiles

Hi, I’ve got a problem with enemy-projectile collision.
Enemy spatial has own control with detecting non-physical collision.

Enemy ControlUpdate

for(int i = 0; i < lev.addObject.bulletList.size(); i++)
        {
            bullCol = lev.addObject.bulletList.get(i).getWorldBound();
        }

        if (!lev.addObject.bulletList.isEmpty())
        if (spatial.getWorldBound().intersects(bullCol))
        {
            lev.addObject.addExplosion(spatial.getLocalTranslation()); //explosion fx
            lev.rootNode.detachChild(spatial);
        }
        else
        {
            spatial.move(0, 0, speed * tpf);
        }

I made projectile List (bulletList) to store all projectile spatials. The for loop should test each of projectiles and check collision with the body of enemy.

Problem is that enemies collide just with some of projectiles and other projectiles are ignored (running through them with no effect)

How to make collision with many spatials of same kind (projectiles for example)?

Sorry, just noticed my mistake in for loop…
My bad :smiley:

So this is how it works fine for me:

Enemy ControlUpdate:

for(int i = 0; i < lev.addObject.bulletList.size(); i++)
        {
            bullCol = lev.addObject.bulletList.get(i).getWorldBound();
            
            if (!lev.addObject.bulletList.isEmpty())
            if (spatial.getWorldBound().intersects(bullCol))
            {
                lev.addObject.addExplosion(spatial.getLocalTranslation()); //explosion fx
                lev.rootNode.detachChild(spatial);
            }
        }

Having a separate object and spatial for every bullet probably isn’t a good idea anyway though. Most in-game shooting is don via ray tests.

I understand, but it’s necessary for my “Scrolling shooter” game style.

Here is screen shot…

1 Like

You could try instanced stuff, see the TestInstanced in the examples.

Well I can not find this “TestInstanced” example in JmeTests and even on this site :frowning:
I’m kinda new to it and I know that I need to learn a lot about optimization topic.
So maybe few links would helped me very much :smile:

I’m not sure if it was already in 3.0 or is only in the upcoming 3.1.
If it is the later, just make a note to give it a try once 3.1 is released.

Thanks! I’ve tried it but…

Error: package does not exist

import com.jme3.scene.instancing.InstancedGeometry;
import com.jme3.scene.instancing.InstancedNode;

So it will be in jME 3.1…

Anyway - if I understand it right, I create Nodes for repeated objects (projectiles, enemies) - attach geometries to them. Then attach these few main Nodes to the RootNode.
And then hope it will reduce number of objects in the scene.