I’m generating terrain generally like in TerrainFractalGridTest, however, I want collisions.
It’s working however in some angles with the terrain the character falls bellow the terrain into the endless void.
What do?
Terrain collisions:
[java]
if (usePhysics) {
terrain.addListener(new TerrainGridListener() {
public void gridMoved(Vector3f newCenter) {
}
public Material tileLoaded(Material material, Vector3f cell) {
return material;
}
public void tileAttached(Vector3f cell, TerrainQuad quad) {
HeightfieldCollisionShape quadShape = new HeightfieldCollisionShape(quad.getHeightMap(), terrain.getLocalScale());
quad.addControl(new RigidBodyControl(quadShape, 0));
app.getStateManager().getState(BulletAppState.class).getPhysicsSpace().add(quad);
}
public void tileDetached(Vector3f cell, TerrainQuad quad) {
app.getStateManager().getState(BulletAppState.class).getPhysicsSpace().remove(quad);
quad.removeControl(RigidBodyControl.class);
}
});
}
[/java]
Character:
[java]
// Add a physics character to the world
CapsuleCollisionShape cap = new CapsuleCollisionShape(0.5f, 3f);
control = new CharacterControl(cap, .1f);
app.getStateManager().getState(BulletAppState.class).getPhysicsSpace().enableDebug(app.getAssetManager());
control.setPhysicsLocation(new Vector3f(0, 1, 0));
character = new Node(“character node”);
Spatial model = app.getAssetManager().loadModel(“Models/man.j3o”);
//make model coincide with collision box
model.setLocalTranslation(0.20f, -2.0f, -0.8f);
model.scale(0.05f);
control.setGravity(100);
character.addControl(control);
character.attachChild(model);
bulletAppState.getPhysicsSpace().add(control);
app.getRootNode().attachChild(character);
[/java]
Play with the stepHeight of the character and make sure you do ot push it into the terrain with the walkdirection.
I’m not sure what you mean, what class has that method?
Is that exemplified on any of the tests or somewhere else?
Sometimes when the character is falling a big distance into a slope, he enters the terrain and stays partially bellow the terrain, will playing with the stepHeight fix that as well?
My first impression what that somehow the collision shape (or whatever the correct name is) for the terrain is too thin, is that possible?
Sorry for my noobishness.
bump
I’m not sure if a step height is built in.
You will have to do that for your character: checking a step height.
Look at your current spot and get its height. Look at the spot you are moving to this frame and get the height there. If it is beyond a certain amount, don’t move forward.
stepHeight
ya what normen said
I don’t use physics so I’m just guessing.