BoundingCollisionResults problem

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!

I have been trying a lot of different methods to detect collisions and I have not achieved any proper result. Can anyone help me?



Thank you.

Taken from https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:collision_and_intersection

...Assume you have two collidables a and b and want to detect collisions between them. The collision parties can be Geometries, Nodes with Geometries attached (including the rootNode), Planes, Quads, Lines, or Rays...



[java]
protected void simpleUpdate(float interpolation) {

[...]

if(enemigoCreado == false){
[..]
}
else{
CollisionResults results = new CollisionResults();
if (d!= null)
d.getThatSphereOfYours_MustBeGeometry().collideWith(ees.getEnemigo().getThatBoxOfYours_MustBeGeometry, results);
System.out.println("
Collisions? " + results.size() + "
");
for (int i = 0; i < results.size(); i++) {
// For each hit, we know distance, impact point, name of geometry.
float dist = results.getCollision(i).getDistance();
Vector3f pt = results.getCollision(i).getWorldContactPoint();
String hit = results.getCollision(i).getGeometry().getName();
System.out.println("* Collision #" + i);
System.out.println(" Collision with " + hit + " at " + pt + ", " + dist + " wu away.");
}
}
}
[/java]

hope that helps