Hello,
I’m working in my first project with JME and I’m having some problemas with collision management.
I’m just trying to achieve that a message appears in the output prompt when a box (EnemigoEstaticoSuelo) and a sphere(Disparo) intersect.
I have tried to use “intersects()” and with BoundingCollisionResults, and it’s not working. I am a novice in game programming and I am stuck at that point.
This is part of my code:
[java]protected final void initGame() {
/** Create rootNode */
rootNode = new Node(“rootNode”);
/**
- Create a ZBuffer to display pixels closest to the camera above
- farther ones.
/
ZBufferState buf = display.getRenderer().createZBufferState();
buf.setEnabled(true);
buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
rootNode.setRenderState(buf);
// ---- LIGHTS
/* Set up a basic, default light. /
PointLight light = new PointLight();
light.setDiffuse(ColorRGBA.white.clone());
light.setAmbient(ColorRGBA.white.clone());
light.setLocation(new Vector3f(0, 1, 40));
light.setEnabled(true);
/* Attach the light to a lightState and the lightState to rootNode. /
lightState = display.getRenderer().createLightState();
lightState.detachAll();
lightState.setEnabled(false);
lightState.attach(light);
rootNode.setRenderState(lightState);
/* Let derived classes initialize. */
simpleInitGame();
/**
- Update geometric and rendering information for both the rootNode and
- fpsNode.
*/
rootNode.updateGeometricState(0.01f, true);
rootNode.updateRenderState();
results = new BoundingCollisionResults() {
public void processCollisions() {
if (getNumber() > 0) {
System.out.println("Enemigo Hit!: "+getNumber());
}
}
};
}[/java]
[java]protected void simpleUpdate(float interpolation) {
[…]
if(enemigoCreado == false){
if (personaje.getWorldTranslation().getZ()>15){
enemigoCreado = true;
ees = new EnemigoEstaticoSuelo(“Enemigo”);
fase1.attachChild(ees);
}
}
else{
//rootNode.updateGeometricState(interpolation, true);
results.clear();
if (d!= null)
d.calculateCollisions(ees.getEnemigo(), results);
}
}[/java]
In the code, d is an object of the class Disparo, that extends Node and has a Sphere as attribute, ees is an object of the class EnemigoEstaticoSuelo, that extends Node and has a box as attibute.
I have alse tried to call calculateCollisions with d.getBala(), that is the Sphere itself, but it’s not working either.
Do you have any idea of how to solve this?
Thank you!