Character falling into endless void through terrain

This is a copy of another post I made, I think, in the wrong section. So I’m really new to jME and I was trying to make a character walk on the terrain I made. The thing is I’m following a tutorial on YouTube on how to make this but even after writing the code exactly as the video shows, I’m not getting the same results. Some help would be appreciated. Thank you. I don’t know if I can post the link but here it is: - YouTube

And here’s the code:

[java]
public class Main extends SimpleApplication {

public static void main(String[] args) {
Main app = new Main();
app.start();
}
private BulletAppState bulletAppState;
private BetterCharacterControl jugador;
private Node jugadorNodo;

@Override
public void simpleInitApp() {

// Se ajusta la velocidad de la cámara
flyCam.setMoveSpeed(50f);

bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);

// Se crea el mapa
initTerrain();
initLight();

// Se crea el jugador/héroe
initJugador();

}

private void initTerrain() {
Spatial terreno = assetManager.loadModel(“Scenes/primerMapa.j3o”);
RigidBodyControl terrenoControl = new RigidBodyControl(0f);
terreno.addControl(terrenoControl);
bulletAppState.getPhysicsSpace().add(terrenoControl);
rootNode.attachChild(terreno);
}

private void initLight() {
AmbientLight ambient = new AmbientLight();
ambient.setColor(ColorRGBA.White);
rootNode.addLight(ambient);
}

private void initJugador() {
jugadorNodo = new Node(“Jugador”);
jugador = new BetterCharacterControl(0.3f, 1.8f, 70f);
jugadorNodo.addControl(jugador);
bulletAppState.getPhysicsSpace().add(jugador);
rootNode.attachChild(jugadorNodo);
jugador.warp(new Vector3f(0.0f, 20.0f, 0.0f));
}

@Override
public void simpleUpdate(float tpf) {
cam.setLocation(jugadorNodo.getLocalTranslation().add(new Vector3f(0.0f, 1.8f, 0.0f)));
}

@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
[/java]

I had a similar issue when using very small measures: i.e. your player control radius is 0.3f.
See if using a larger scale works, like make everything ten times bigger.

Also, I did not have much luck using the BetterCharacterControl. I would recommend using CharacterControl over BetterCharacterControl.

Hope that helps,
Trevor

Did the larger scale, suggested by @Trevor, work?

Because, I am not 100% sure but as I remember, the collision of a static terrain vs a dynamic object happens on the static terrain triangles nodes, not in the center of each triangle of the terrain collision mesh.

The fix would be to make the terrain have more triangles, so you need to subdivide the terrain more to make it work with the objects colliding on it.

I wonder if we could plug some collision engine that works so precisely like doom3 one?

also check here: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:bullet_pitfalls

@teique said: Did the larger scale, suggested by @Trevor, work?

Because, I am not 100% sure but as I remember, the collision of a static terrain vs a dynamic object happens on the static terrain triangles nodes, not in the center of each triangle of the terrain collision mesh.

The fix would be to make the terrain have more triangles, so you need to subdivide the terrain more to make it work with the objects colliding on it.

I wonder if we could plug some collision engine that works so precisely like doom3 one?

also check here: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:bullet_pitfalls

Note: while you are right to mention that smaller triangles are better, I think your reasoning as to why is a little off. It’s not that collision is done only against the vertexes. It’s that the error rate for small penetrations in the middle of a LARGE triangle are way higher than for a small one.

You can visualize the concept by imagining a 0.01 meter penetration in the middle of a 1 meter triangle as compared to a 0.02 meter penetration. Imagine a line drawn to the nearest vertex (0.5 meters away). The different in the angle is almost a full degree. If you applied the same to a 100 meter triangle then the difference is a tiny fraction of a degree.

Similarly, the math to compute things like the actual height of the triangle at a given point are going to accumulate more errors over long spans than they do over short ones. Given the precision needed for accurate physics (for a 100 different reasons), accumulated small errors like this rapidly overcome 32-bit floats ability to keep up.