Incorrect Collision Detecting (Collision When Ball is Nowhere Near Target)

For some reason in the game I am developing, the collisions seem to be completely incorrect. I use this code to detect the collision between the ball (player) and the pressure pad (this is in the pressure pad class):

    public void collision(PhysicsCollisionEvent event) {
        if (event.getNodeA().getName() == "Player") {
                System.out.println(this + " Collided at Node " + event.getNodeA().getName());
         }
        if (event.getNodeB().getName() == "Player") {
                System.out.println(this + " Collided at Node " + event.getNodeB().getName());
        }
    }

However when I run, even though the ball is nowhere near the pressure pad, it detects a collision and prints that out. Is there anything I am missing or doing incorrectly?

I am grateful for any help :slight_smile:
Thanks

Just a guess, but if you are using a GhostControl it uses the bounding box of the collision shape for collision detection

No, I am using RigidBodyControl, I hope that I am using it correctly :stuck_out_tongue:
I have done about 2 more hours of trying to figure it out to no avail. Any ideas?

Try to enable the debug shape as described here: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:physics

Maybe that will show you what is happening.

That’s what is strange, I enabled that beforehand and nothing is out of place!

I found out something interesting. When I am not touching the cubes or pressure pads the collision is not detected. I use this code to create the cubes and pressure pads for the map (maybe something is static that causes it to be called if I am touching any cube at at all?):

[java]
public Cube(PlayerBall playerBall, AssetManager assetManager, Node rootNode, Type type, BulletAppState bulletAppState, float x, float y, float z) {
super(0f);
this.t = type;
this.xt = x;
this.yt = y;
this.zt = z;
b = new Box(1, 1, 1);
sphereGeo = new Geometry(“Shiny rock”, b);
TangentBinormalGenerator.generate(b); // for lighting effect
sphereMat = new Material(assetManager,
“Common/MatDefs/Light/Lighting.j3md”);
sphereMat.setTexture(“DiffuseMap”,
assetManager.loadTexture(“Textures/wall.png”));
sphereMat.setTexture(“NormalMap”,
assetManager.loadTexture(“Textures/wallnormal.png”));
sphereMat.setBoolean(“UseMaterialColors”, true);
if (type == Type.Normal) {
sphereMat.setColor(“Diffuse”, ColorRGBA.White);
} else if (type == Type.Spawn) {
sphereMat.setColor(“Diffuse”, ColorRGBA.Green);
} else if (type == Type.PressurePlate) {
sphereMat.setColor(“Diffuse”, ColorRGBA.Red);
}
sphereMat.setColor(“Specular”, ColorRGBA.White);
sphereMat.setFloat(“Shininess”, 65f); // [0,128]
sphereGeo.setMaterial(sphereMat);
sphereGeo.setLocalTranslation(new Vector3f(xt, yt, zt));
rootNode.attachChild(sphereGeo);
sphereGeo.addControl(this);
setFriction(1f);
bulletAppState.getPhysicsSpace().add(this);
bulletAppState.getPhysicsSpace().addCollisionListener(this);
this.playerBall = playerBall;
}
[/java]

and this isn’t a voxel engine, just a cube based puzzler.

I’m not sure I’ve fully followed this thread…

but you do know that a collision listener is called for all collisions, right?

The fact that you’ve made your cube also a listener is perhaps misleading. I noticed in your first code you print “this” even though “this” is completely irrelevant to the collisions.

The event says that A and B collided. “this” doesn’t mean anything in that context unless you are testing to see if A == this or B == this.

Ohhhh I get it. I’m sorry, for some reason I thought that the collision was called for whatever rigidbody it implements. Somehow I deluded myself into thinking it had a rigidbody implemented as well. I’m sorry about that. What would i use to check if player and pressurepad/block have collided?