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
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);
}
}
Well I can not find this “TestInstanced” example in JmeTests and even on this site
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
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.