GhostControl help

To detect if 2 objects are overlapping, do both of the objects have to have a ghost control? and does the ghost control supposed to be attached to the bulletAppState physics space?

Yes if you use bullet for collision checks, you can also use the geometry collision checks if you don’t use physics, its not as flexible tho.

ive made it so that when the object that is constantly going down resets its y position if it overlaps another spatial but it doesnt seem to be working.



GhostControl[] controls = new GhostControl[5];

Geometry[] boxes = new Geometry[5];



public void simpleInitApp(){



Box box1 = new Box(Vector3f.ZERO,5,5,5);

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

boxMat.setColor(“Color”,ColorRGBA.Blue);



Box box2 = new Box(Vector3f.ZERO,20,20,20);

Geometry bigBox = new Geometry(“Other Box”,box2);

bigBox.setMaterial(boxMat);

GhostControl bControl = new GhostControl(new BoxCollisionShape(new Vector3f(20,20,20)));

bigBox.addControl(bControl);

bulletAppState.getPhysicsSpace.add(bControl);



for (int a = 0;a <5;a++){

boxes[a] = new Geometry("BOX # " + a,box1);

boxes[a].setMaterial(boxMat);

boxes[a].move(5 * a,25,0);

rootNode.attachChild(boxes[a]);

controls[a] = new GhostControl(new BoxCollisionShape(5,5,5);

boxes[a].addControl(controls[a]);

bulletAppState.getPhysicsSpace.add(controls[a]);

}

}



public void simpleUpdate(){

for (int a = 0;a < 5;a++){

boxes[a].move(0,-1,0);

if (controls[a].getOverLappingCount() > 0){

boxes[a].move(0,20,0);

}

}

}

the last for loop didnt show up properly for some reason its supposed to say:



if (controls[a].getOverLappingCountr() > 0){

boxes[a].move(0,20,0);

}



and the bigBox is attached to the rootNode, but that didnt show up either on the above post.