JME3 Exploding projectiles

I want to fire projectiles then have them explode whenever they collide with anything, and disappear of course.



I’m having a problem finding if they collide.



I’m using

[java] /* create a new cannon ball. /

Geometry ball_geo = new Geometry(“cannon ball”+counter, cannonball);

ball_geo.setMaterial(stone_mat);

PhysicsNode cannonballNode = new PhysicsNode(

ball_geo, // geometry

cannonballCollisionShape, // collision shape

1.0f); // mass

/
* position the cannon ball and activate shadows /

cannonballNode.setLocalTranslation(cam.getLocation().add(cam.getDirection().add(cam.getDirection())).subtract(new Vector3f(0, 0.5f, 0).add(new Vector3f(.25f, 0, 0))));

cannonballNode.setShadowMode(ShadowMode.CastAndReceive);

/
* Attach the cannon call to the scene and accelerate it. */

playerProjectileNode.attachChild(cannonballNode);

getPhysicsSpace().add(cannonballNode);

cannonballNode.setLinearVelocity(cam.getDirection().mult(100));[/java]



this for my projectile (from the tutorial) but I can’t use this line;

[java]rootNode.collideWith(playerProjectileNode, results);[/java]



since it wants a boundingvolume, sweepingsphere, or ray… help please.



Isn’t there a better method for setting an event to happen when PhysicsNodes of a certain category collide with others?

Looky here. :smiley:

Very nice thanks normen, I’m having a bit of trouble with my own effects; no time tonight as I’m off to bed but I’ll post them up with the error incase someone glancing by sees the flaw in my logic and corrects me :slight_smile:



This makes my fire at location given by vector origin;

[java] public void makeFire(Vector3f origin) {

ParticleEmitter fire = new ParticleEmitter(“Emitter”, ParticleMesh.Type.Triangle, 30);

Material mat_red = new Material(assetManager, “Common/MatDefs/Misc/Particle.j3md”);

mat_red.setTexture(“m_Texture”, assetManager.loadTexture(“Effects/Explosion/flame.png”));

fire.setMaterial(mat_red);

fire.setImagesX(2);

fire.setImagesY(2); // 2x2 texture animation

fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f)); // red

fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f)); // yellow

fire.setStartVel(new Vector3f(0, 2, 0));

fire.setStartSize(1.5f);

fire.setEndSize(0.1f);

fire.setGravity(0);

fire.setLowLife(0.5f);

fire.setHighLife(3f);

fire.setVariation(0.3f);

fire.setCullHint(CullHint.Never);

rootNode.attachChild(fire);

}[/java]



Likewise with my debris;

[java] public void makeDebris(Vector3f origin) {

ParticleEmitter debris = new ParticleEmitter(“Debris”, ParticleMesh.Type.Triangle, 10);

Material debris_mat = new Material(assetManager, “Common/MatDefs/Misc/Particle.j3md”);

debris_mat.setTexture(“m_Texture”, assetManager.loadTexture(“Effects/Explosion/Debris.png”));

debris.setMaterial(debris_mat);

debris.setImagesX(3);

debris.setImagesY(3); // 3x3 texture animation

debris.setRotateSpeed(4);

debris.setSelectRandomImage(true);

debris.setStartVel(new Vector3f(0, 4, 0));

debris.setStartColor(new ColorRGBA(1f, 1f, 1f, 1f));

debris.setGravity(6f);

debris.setVariation(.60f);

rootNode.attachChild(debris);

debris.emitAllParticles();

}[/java]



However both are giving my an error;

[java]SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,6,main]

java.lang.NullPointerException: Geometry: Emitter has null mesh

at com.jme3.scene.Geometry.updateWorldBound(Geometry.java:180)

at com.jme3.scene.Spatial.updateGeometricState(Spatial.java:625)

at com.jme3.scene.Node.updateGeometricState(Node.java:185)

at mygame.Main.simpleUpdate(Main.java:390)

at com.jme3.app.SimpleBulletApplication.update(SimpleBulletApplication.java:280)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:144)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:133)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:198)

at java.lang.Thread.run(Thread.java:619)[/java]



and the same for debris but with “Emitter” replaced with “Debris”. Night and thanks ahead of time for any responses!