Im playing around with terrain. I can spawn my CharacterControl and walk round the world really nicely but usually end up glitching through the terrain and falling into the void.
- Physics works perfectly for a few minutes
- I am nowhere near the edge of the terrain grid
- Usually in steep area or when climbing up a hill
- Flatter areas seem unaffected
- No other physics objects in the scene
- No error messages or debug info
the only “Non standard thing” im doing is using “RawHeightMap.FORMAT_16BITLE” so i can get good height
My character control code is taken from the Q3 example, and looks like this
public void SpawnPlayer(){
if (this.platerisactive == false){
System.out.println(" AppState_LocalPlayer SpawnPlayer() sp="+spawnpoint);
//capsuleShape = new CapsuleCollisionShape(0.4f, 1.8f, 1);
//player = new CharacterControl(capsuleShape, 0.05f);
player = new PhysicsCharacter(new SphereCollisionShape(0.5f), .01f);
player.setJumpSpeed(25);
player.setFallSpeed(30);
player.setGravity(100);
player.setPhysicsLocation(spawnpoint);
//add to physicsspace
ps.add(player);
update() uses the walk method and is not affecting the scenegraph
@Override
public void update(float tpf) {
if (platerisactive){
this.updateplayer(tpf);
}
}
private void updateplayer(float tpf){
//set walking speed
playerMoveSpeed = ( PlayerMovementSpeed * tpf);
//get which way the player is facing in game world
camDir = sapp.getCamera().getDirection().mult(playerMoveSpeed);
camLeft = sapp.getCamera().getLeft().mult(playerMoveSpeed);
//reset the direction to move .. this will prob change each frame anyway
walkDirection.set(0, 0, 0);
if(PlayerMoveForwards){
walkDirection.addLocal(camDir);
// System.out.println("2-FWDS");
}
if(PlayerMoveBackwards){
walkDirection.addLocal(camDir.negate());
//System.out.println("2-right");
}
if(PlayerMoveLeft){
walkDirection.addLocal(camLeft);
//System.out.println("2-back");
}
if(PlayerMoveRight){
walkDirection.addLocal(camLeft.negate());
//System.out.println("2-lft");
}
walkDirection.setY(0);
player.setWalkDirection(walkDirection);
//move the blue box to indicate player
PlayerLocation = player.getPhysicsLocation();
sapp.getRootNode().getChild("PlayerBlueBox").setLocalTranslation(PlayerLocation);
sapp.getCamera().setLocation(player.getPhysicsLocation());
}
My terrain code is taken from the terrain examples and looks like this
this.terrain = new TerrainQuad("terrain_"+xpos+"_"+zpos, 33, 513, aheightmap.getHeightMap());
this.terrain.setMaterial(this.terrainMaterial);
this.terrain.setLocalScale(this.terrainscalexz, this.terrainscaley, this.terrainscalexz); // scale
this.terrain.setLocalTranslation(this.worldcenter);
TerrainLodControl control = new TerrainLodControl(terrain,m.getCamera());
this.terrain.addControl(control);
m.getRootNode().attachChild(this.terrain);
//set up collision detection for the scene by creating a static RigidBodyControl with mass zero.
this.terrain.addControl(new RigidBodyControl(0));
m.getStateManager().getState(BulletAppState.class).getPhysicsSpace().addAll(terrain);
m.getRootNode().attachChild(this.addPlane());
any help is appreciated. ive been struggling for days on this one