RigitBody and terrain collision

Hello everyone,

as new and exited with the jmonkey power, i tried to combine some of the beginners tutorials.
The town.zip was loaded and used as terrain with RigidBody as control. The “player” creates sphere bullets that have also RigidBody of mass 1 and LinearVelocity set.

Now, why the collision does not always work? Do i need to change the bulletAppState.getPhysicsSpace().setAccuracy ?

Apart from that, i tried to make the test even cooler(hotter in fact :grinning: ) and add flames on collision with terrain. So i used inside the bullet controller:

if ((!on_fire) && (this.spatial.collideWith(this.app.getRootNode().getChild(“main-scene_node”).getWorldBound(), results)>0))
{
CollisionResult closest = results.getClosestCollision();
System.out.println("What was hit? " + closest.getGeometry().getName() );
for (int i=0; i < results.size();i++)
{
if (!results.getCollision(i).getGeometry().getName().equals(“bullet”))
{
boom_time=0;
break;
}
}
}

is seems that it collides with itself!!??? Collision with the terrain is not recorded :frowning:
Should i use ghostcontrol instead?

Thank you for your time! i hope that this make sense!

Tried the GhostControl and now it seems to collide with the terrain (in the air???)

if (this.spatial.getControl(GhostControl.class).getOverlapping(i).equals(this.app.getRootNode().getChild(“main-scene_node”).getControl(RigidBodyControl.class)))

What i am missing??

Thank you!

First, dont use ghostcontrol.
Second, for terrian, use mass = 0.
Now, what are you using in the objects physics ? Kinematic ? Just Rigid Body ?

Thank you for your reply! Yes i used mass of zero as shown below:

    assetManager.registerLocator("assets/Scenes/town.zip", ZipLocator.class);
    Spatial sceneModel = assetManager.loadModel("main.scene");
    sceneModel.setLocalScale(2f);
    this.app.getRootNode().attachChild(sceneModel);
    
    CollisionShape sceneShape =CollisionShapeFactory.createMeshShape((Node) sceneModel);
    sceneModel.addControl(new RigidBodyControl(sceneShape, 0));
    init_define_physics(sceneModel.getControl(RigidBodyControl.class));

I used just rigidbody:

    ball_phy = new RigidBodyControl(1f);
    ball_geo.addControl(ball_phy);
    this.app.get_bulletAppState().getPhysicsSpace().add(ball_phy);
    float speed=position.getUserData("Speed");
    ball_phy.setLinearVelocity(this.app.getCamera().getDirection().mult(speed));

The strange is that when i replaced the terrain with a geometry (box), the bullet was colliding only when touched the ground (as supposed to).

Thanks again!

Is town.zip your creation ?
It may be an problem in your model, try to change it in blender.
I saw other new players having this kind of problem, I never had, but I guess you may need to do some “fix” like make an biguer box behind the ground.
Bullet is another engine, you will not find much help here in the forum about bullet problems, you may consider post some questions in their forum as well.

No it is from the beginners tutorials(Collision detection).
Just thought that it was something common or known issue :slight_smile:
The same behavior can be noticed when using heightmap (at least in my case).

I have already used the debugger of the Bullet, to view the triangles, but nothing strange is found in the air!

Now, regarding the collision accuracy, should it be changed? (sometimes the bullets are crossing the buildings)

Good news wagfeliz! It seems that i have found the solution :smile:

Instead of

if ((!on_fire) &&
(this.spatial.collideWith(this.app.getRootNode().getChild(“main-scene_node”).getWorldBound(),
results)>0))

reversed it to

    if ((!on_fire) && (((Node)this.app.getRootNode().getChild("main-scene_node")).collideWith(this.spatial.getWorldBound(), results)>0))