Collision box not moving with spatial


I’m going to make this clear from the outset. I’m not a jMonkey wizard. I just downloaded the sdk a few days ago and I’m working on a school project using the engine. I’m going to try and make the issue I am having as clear as possible

I have a simple scene with a wall, a ball, and a tennis racket. Here’s a picture:
I have a key wired to make the ball start moving towards the wall when I push it. I have CollisionShapes around both the wall and the ball. I want the ball to stop moving when it touches the wall.

The ball always goes through the wall even though I have collision around both. Now, I have bulletAppState.setDebugEnabled(); set to true. I can see the collision boxes.

You can see that the collision box around the ball is not moving with the ball. I do not understand why this is happening. I have the collision box attached to the Spatial representing the ball written this way:
CollisionShape wallShape = CollisionShapeFactory.createBoxShape(wall);
wallCollision = new RigidBodyControl(wallShape, 0);

    CollisionShape ballShape = CollisionShapeFactory.createBoxShape(ball);
    ballCollision = new RigidBodyControl(ballShape, 0);

But still, the collision box does not move with the ball. Is there something here that I’m missing? Here’s the full code:


I’m pretty sure you need to apply forces / set the location on the RigidBody control and not the spatial. Moving the spatial doesn’t change the physics engine.


The mass of your ball should not be 0 also.


I had a question about moving an object too. Here’s how I do it in my code:

            //ballNode.move(new Vector3f( (ballNode.getLocalTranslation().getX()), (ballNode.getLocalTranslation().getY()), (ballNode.getLocalTranslation().getZ()  - .00002f)));
           ballNode.setLocalTranslation(new Vector3f( (ballNode.getLocalTranslation().getX()), (ballNode.getLocalTranslation().getY()), (ballNode.getLocalTranslation().getZ()  - .00002f)));

Notably I use the setLocalTranslation() method instead of the move() method. I thought that there might be a problem with this. Does the physics system only work on movements done with the move() method?



Using the move method you would still only be setting the location on the spatial which doesn’t change the physics object you created. You need to use the RigidBody Control. I would suggest looking at the tutorial thetoucher linked and play around with that example.