Hi everyone ,
I got a model (with a chase camera ) who is walking on a terrain (the basic one ) and the character can’t claim montain until i released the key , otherwise it’s falling into emptiness.
It’s working when the character is climbing down by the way …
Here are my declarations :
[java]
public static Spatial perso
private BulletAppState bulletAppState;
private PhysicsCharacterNode character;
private PhysicsNode Geoterrain;
private Node terrainPhysicsNode;
[/java]
Here’s is the Terrain code :
[java]
public void SetupTerrain(){
mat_terrain = new Material(assetManager, “Common/MatDefs/Terrain/Terrain.j3md”);
mat_terrain.setTexture(“m_Alpha”, assetManager.loadTexture(“Textures/Terrain/splat/alphamap.png”));
Texture grass = assetManager.loadTexture(“Textures/Terrain/splat/grass.jpg”);
grass.setWrap(WrapMode.Repeat);
mat_terrain.setTexture(“m_Tex1”, grass);
mat_terrain.setFloat(“m_Tex1Scale”, 64f);
Texture dirt = assetManager.loadTexture(“Textures/Terrain/splat/dirt.jpg”);
dirt.setWrap(WrapMode.Repeat);
mat_terrain.setTexture(“m_Tex2”, dirt);
mat_terrain.setFloat(“m_Tex2Scale”, 32f);
Texture rock = assetManager.loadTexture(“Textures/Terrain/splat/road.jpg”);
rock.setWrap(WrapMode.Repeat);
mat_terrain.setTexture(“m_Tex3”, rock);
mat_terrain.setFloat(“m_Tex3Scale”, 128f);
AbstractHeightMap heightmap = null;
Texture heightMapImage = assetManager.loadTexture(“Textures/Terrain/splat/mountains512.png”);
heightmap = new ImageBasedHeightMap(
ImageToAwt.convert(heightMapImage.getImage(), false, true, 0));
heightmap.load();
terrain = new TerrainQuad(“terrain”, 65, 513, heightmap.getHeightMap());
/** 4. We give the terrain its material, position & scale it, and attach it. /
terrain.setMaterial(mat_terrain);
terrain.setLocalScale(1f, 1f, 1f);
/* 5. The LOD (level of detail) depends on were the camera is: /
List<Camera> cameras = new ArrayList<Camera>();
cameras.add(getCamera());
TerrainLodControl control = new TerrainLodControl(terrain, cameras);
terrain.addControl(control);
terrain.setModelBound(new BoundingBox());
terrain.updateModelBound();
TerrainPhysicsShapeFactory factory = new TerrainPhysicsShapeFactory();
terrainPhysicsNode = factory.createPhysicsMesh(terrain);
terrainPhysicsNode.attachChild(terrain);
rootNode.attachChild(terrainPhysicsNode);
bulletAppState.getPhysicsSpace().add(terrainPhysicsNode);
[/java]
Here’s is my character class :
[java]
public void setupModel(){
perso = (Node) assetManager.loadModel(“Models/Oto/Oto.mesh.xml”);
character = new PhysicsCharacterNode(new CapsuleCollisionShape(1.5f, 2f ,1), 1f);
character.attachChild(perso);
character.setJumpSpeed(20); //10 default
character.setFallSpeed(30); //30 default
character.setGravity(30); //30 default
perso.scale(0.55f,0.55f,0.55f);
character.setLocalTranslation(-50.0f,30f,-3.0f);
Material mat = new Material(assetManager, “Common/MatDefs/Misc/ShowNormals.j3md”);
perso.setMaterial(mat);
rootNode.attachChild(character);
Material mat_lit = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);
mat_lit.setTexture(“m_DiffuseMap”,assetManager.loadTexture(“Textures/Terrain/Gallet.png”));
mat_lit.setTexture(“m_NormalMap”,assetManager.loadTexture(“Textures/Terrain/Gallet_normal.png”));
mat_lit.setFloat(“m_Shininess”,5f);
perso.setMaterial(mat_lit);
rootNode.attachChild(character);
bulletAppState.getPhysicsSpace().add(character);
}
[/java]
Here is a sample of my command control code
[java]
if(name.equals(“Haut”)&& character.onGround()){ // <== Here is what is interesting
character.move(0.005fc.x,0,0.005f*c.z);
System.out.println(“Position perso :”+ character.getLocalTranslation());
directionperso.lookAt(cam.getDirection(),Vector3f.UNIT_Y);
perso.setLocalRotation(directionperso);
updateCamera();
}
[/java]
I’m thinking about an issue in controller but i’m not sure.
I did a test without animation it’s exactly the same thing , can anyone light me ?
Thanks a lot in advance ,
Regards ,
Danath
You should not move the physicsCharacter like a spatial with move() or setLocalTranslation() but set the walkDirection. All other movement is like the object is “warping” from spot to spot for the physics, which is guaranteed to yield wrong results.
i don’t understand how to move the character with the WalkDirection since i don’t want my character to move with WSQD should i rewrite the flycam class ? i really don’t want to touch on this :/.
Or should i put the characterposition on another vector that i’ll manipulate ?
You cannot expect the physics to work correctly if you dont move the entities in a physic-compatible way. Using walkDirection is simple. Just set the walkDirection once and the character will move into that direction with the given speed vector until you set it to zero again. If you dont want to do that you shouldnt use physics at all and just use the normal ray and bounding volume vs triangle collision detection.
I’ll check out , thanks a lot normen to answer that quickly
It works thank you very much normen