Player(character) is falling down somewhere when walking on a ground and it is not exactly on the ground

hai one and all,
I created a city and defined as rigid body and a character with capsuleCollisionShape but my character is not exactly stick to ground and it is falling through the ground.
suggest me the way to get out of this…
Thank you allllll…

Maybe this could help

Rigid bodies fall through ground

This usually happens if the ground physics object has large triangles or consists of a large BoxCollisionShape.

Workaround:
- For meshes with large triangles - Subdivide the mesh in a model editor such as Blender.
- For large boxes - seperate into smaller boxes or use a MeshCollisionShape for terrain instead of BoxCollisionShape.

http://wiki.jmonkeyengine.org/doku.php/jme3:advanced:bullet_pitfalls

1 Like

thank you I will edit my city in blender and I’ll check

hai Riccardo,
I subdivided my city’s ground in blender still I’m falling!!!
I have used mesh collision shape itself but…

Could you provide a screenshot of the scene with BulletAppState’s debug enabled?

here is the screenshot

Did you set

bulletAppState.setDebugEnabled(true);

as I asked, before taking the screenshot?
Because if you did, your scene doesn’t contain any rigidbody…

ya I setted that but…

Does your character fall immediately through the terrain? Or after a while you are walking around?

After walking some while but there is no fault with walk direction and veiw direction

Can you post your code?

Does your character gradually move through the floor? Or is it always like it is in the screen shot? If the later is true, then it’s how the mesh is centered (or not centered) in the collision shape.

T0neg0d

My character gradualy move through ground and somewhere it will fall…

How are you initializing the physics state?

t0neg0d

I’m out of front to my pc I’ll upload the src code when I’ll infront…

Here is the code

      package mygame;

      import com.jme3.animation.AnimChannel;
      import com.jme3.animation.AnimControl;
      import com.jme3.animation.LoopMode;
      import com.jme3.app.SimpleApplication;
      import com.jme3.audio.AudioNode;
      import com.jme3.audio.Environment;
      import com.jme3.bullet.BulletAppState;
      import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
      import com.jme3.bullet.collision.shapes.CollisionShape;
      import com.jme3.bullet.control.CharacterControl;
      import com.jme3.bullet.control.RigidBodyControl;
      import com.jme3.bullet.util.CollisionShapeFactory;
      import com.jme3.collision.CollisionResult;
      import com.jme3.collision.CollisionResults;
      import com.jme3.font.BitmapText;
      import com.jme3.input.ChaseCamera;
      import com.jme3.input.KeyInput;
      import com.jme3.input.MouseInput;
      import com.jme3.input.controls.ActionListener;
      import com.jme3.input.controls.AnalogListener;
      import com.jme3.input.controls.KeyTrigger;
      import com.jme3.input.controls.MouseAxisTrigger;
      import com.jme3.input.controls.MouseButtonTrigger;
      import com.jme3.light.AmbientLight;
      import com.jme3.light.DirectionalLight;
      import com.jme3.math.ColorRGBA;
      import com.jme3.math.Quaternion;
      import com.jme3.math.Vector3f;
      import com.jme3.renderer.RenderManager;
      import com.jme3.scene.Node;
      import com.jme3.ui.Picture;
      import com.jme3.util.SkyFactory;

      /**
       * test
       * @author normenhansen
       */
      public class Main extends SimpleApplication {

public static void main(String[] args) {
    Main app = new Main();
    app.start();
}
  private AnimControl control;
  private AnimControl control1;
  private AnimChannel channel;
  private AnimChannel channel1;
  private RigidBodyControl landscape;
  private BulletAppState bulletAppState;
  private CharacterControl character;
  private CharacterControl character1;
  private CharacterControl character2;
  private CharacterControl character3;
  private CharacterControl character4;
  private CharacterControl character5;
  private CharacterControl character6;
  private Vector3f walkDirection = new Vector3f();
  private Vector3f viewDirection = new Vector3f();
  private boolean left = false, right = false, up = false, down = false, lmb = false, rmb = false, hud = false, n = false;
  ChaseCamera chaseCam;
  Node player;
  Node enemy1;
  Node enemy2;
  Node enemy3;
  Node enemy4;
  Node enemy5;
  Node enemy6;
 // Spatial scene;
  Node city;
  
  Node compassNode3 = new Node("compass3");
  //Geometry mark;
  
  
  Node compassNode1 = new Node("compass1");
  Node compassNode2 = new Node("compass2");
  Picture compassPic1, compassPic2, compassPic3;
  Quaternion q1 = new Quaternion(), q2 = new Quaternion();
  float rot1 = 0.1f, rot2 = 0;
  //float x = 0f, y = 0f, z = 0;
  float c=0f;

  private Vector3f camDir = new Vector3f();
  private Vector3f camLeft = new Vector3f();
  private AudioNode audio_nature;
  private AudioNode audio_nature1;
  private AudioNode audio_nature2;
  private AudioNode audio_nature3;
  private AudioNode boom;
  
@Override
public void simpleInitApp() {
    
    
    flyCam.setEnabled(false);
    bulletAppState = new BulletAppState();
    bulletAppState.setDebugEnabled(true);
    //bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
    stateManager.attach(bulletAppState);
    
    city =(Node) assetManager.loadModel("Models/city_1.j3o");
    city.setLocalScale(500, 600, 700);
    city.setLocalTranslation(0, 0, 0);
    CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node) city);
    landscape = new RigidBodyControl(sceneShape, 0);
    city.addControl(landscape);
      
    CapsuleCollisionShape capsule = new CapsuleCollisionShape(0.2f, 4f, 1);
    character = new CharacterControl(capsule, 0.01f);
    player = (Node) assetManager.loadModel("Models/gun/Cube.mesh.xml");
    player.setMaterial( assetManager.loadMaterial("Materials/player.j3m"));
    player.setLocalScale(0.5f);
    player.setLocalTranslation(-50f, 4, 0);
    player.addControl(character);
    
    CapsuleCollisionShape capsule1 = new CapsuleCollisionShape(0.2f, 4f, 1);
    character1 = new CharacterControl(capsule1, 0.05f);
    enemy1 = (Node) assetManager.loadModel("Models/enemy/enem.mesh.xml");
    enemy1.setMaterial( assetManager.loadMaterial("Textures/enem.j3m"));
    enemy1.setLocalScale(0.1f);
    enemy1.setLocalTranslation(-60f, 3.3f, 130f);
    enemy1.addControl(character1);
    
    chaseCam = new ChaseCamera(cam, player, inputManager);
    chaseCam.setInvertVerticalAxis(inputEnabled);
    chaseCam.setChasingSensitivity(10f);
    chaseCam.setToggleRotationTrigger(new MouseAxisTrigger(MouseInput.AXIS_X, true));
    chaseCam.setRotationSensitivity(10f);
    chaseCam.setZoomSensitivity(50);
       //       chaseCam.setZoomInTrigger(new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    chaseCam.setDefaultDistance(40);
    
    
    control = player.getControl(AnimControl.class);
    channel = control.createChannel();
    channel.setAnim("stand");
    
    setDisplayStatView(false);
    setDisplayFps(false);
    
    
    initLight();
    initKeys();
    initAudio();
    rootNode.attachChild(player);
    rootNode.attachChild(city);
    rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/360sky-Free.jpg", true));
    bulletAppState.getPhysicsSpace().add(landscape);
    bulletAppState.getPhysicsSpace().add(character);
   //   rootNode.attachChild(scene);
}


public void initLight(){

AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(2.0f));
rootNode.addLight(al);

DirectionalLight dl = new DirectionalLight();
dl.setColor(ColorRGBA.White);
dl.setDirection(new Vector3f(-5f, -5f, -5f).normalizeLocal());
rootNode.addLight(dl);

}

public void initKeys(){
inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping("Hud", new KeyTrigger(KeyInput.KEY_H));
inputManager.addMapping("New", new KeyTrigger(KeyInput.KEY_N));
inputManager.addMapping("Aim", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
inputManager.addMapping("Fire", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addMapping("rot", new MouseAxisTrigger(MouseInput.AXIS_X, true));

inputManager.addListener(action, "Left");
inputManager.addListener(action, "Right");
inputManager.addListener(action, "Up");
inputManager.addListener(action, "Down");
inputManager.addListener(action, "Hud");
inputManager.addListener(action, "New");
inputManager.addListener(action, "Aim");
inputManager.addListener(action, "Fire");
inputManager.addListener(action, "rot");

}

private ActionListener action = new ActionListener() {

      public void onAction(String binding, boolean isPressed, float tpf) {
          
          if(binding.equals("Aim")){
              rmb = isPressed;
          }
          
          if(binding.equals("Fire")){
              lmb = isPressed;
          }
          
           if(binding.equals("Hud")){
              hud = isPressed;
          }
           
           if(binding.equals("New")){
              n = isPressed;
          }
          
          if (binding.equals("Left")) {
            left = isPressed;
          } 
          else if (binding.equals("Right")) {
            right= isPressed;
          } 
          else if (binding.equals("Up")) {
            up = isPressed;
          } 
          else if (binding.equals("Down")) {
            down = isPressed;
          } 
          if(binding.equals("rot")){
              character.setViewDirection(cam.getDirection());
          }
    }
  };
    

@Override
public void simpleUpdate(float tpf) {
    camDir.set(cam.getDirection()).multLocal(0.2f);
    camLeft.set(cam.getLeft()).multLocal(0.2f);
    walkDirection.set(0, 0, 0);   
  
    if(n) {
        c = c+1;
        if(c == 1){
            n = false;
            audio_nature.stop();
            audio_nature1.play();
        }
         if(c == 2){
             n = false;
            audio_nature1.stop();
            audio_nature2.play();
        }
          if(c == 3){
            n = false;
            audio_nature2.stop();
            audio_nature3.play();
        }
         if(c == 4){
            c = 0f;
            n = false;
            audio_nature3.stop();
            audio_nature.play();
        }
    }
    
     
    
    if(lmb) {
     
          boom.play();
     }
        
    if(hud) {
guiNode.attachChild(compassNode3);
    hud = false;
    }
    else
    {
    guiNode.detachChild(compassNode3);
    }   
      //	compassNode3.setLocalTranslation(650,400,-1);
    
    if (left) {
        walkDirection.set(camLeft);
        viewDirection.set(camLeft);
    }
    if (right) {
        walkDirection.set(camLeft.negate());
        viewDirection.set(camLeft.negate());          
    }
    if (up) {
        camDir.y = 0;
        walkDirection.set(camDir);
        camDir.y = 0;
        viewDirection.set(camDir);
        }
    if (down) {
        camDir.y = 0;
        walkDirection.set(camDir.negate());
        camDir.y = 0;
        viewDirection.set(camDir.negate());
    }
    character.setWalkDirection(walkDirection);
    character.setViewDirection(viewDirection);
    cam.setLocation(character.getPhysicsLocation());
    
    if (walkDirection.length() == 0) {
        if (!"stand".equals(channel.getAnimationName())) {
            channel.setAnim("stand", 1f);
        }
    }
    else  {
        if(!"walk".equals(channel.getAnimationName())){
            channel.setAnim("walk");      
        }
    }        
    
      }

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

 private void initAudio() {

/* nature sound - keeps playing in a loop. */
audio_nature = new AudioNode(assetManager, "Sounds/music.wav", true);
audio_nature.setLooping(false);  // activate continuous playing
audio_nature.setPositional(false);   
audio_nature.setVolume(3);
rootNode.attachChild(audio_nature);
audio_nature.play(); // play continuously!

audio_nature1 = new AudioNode(assetManager, "Sounds/ad1.wav", true);
audio_nature1.setLooping(false);  // activate continuous playing
audio_nature1.setPositional(false);   
audio_nature1.setVolume(3);
rootNode.attachChild(audio_nature1);
       //   audio_nature1.play();

audio_nature2 = new AudioNode(assetManager, "Sounds/ad2.wav", true);
audio_nature2.setLooping(false);  // activate continuous playing
audio_nature2.setPositional(false);   
audio_nature2.setVolume(3);
rootNode.attachChild(audio_nature2);
       //   audio_nature2.play();

audio_nature3 = new AudioNode(assetManager, "Sounds/music.wav", true);
audio_nature3.setLooping(false);  // activate continuous playing
audio_nature3.setPositional(false);   
audio_nature3.setVolume(3);
rootNode.attachChild(audio_nature3);
       //   audio_nature3.play();

boom = new AudioNode(assetManager, "Sounds/Fire.wav", true);
boom.setLooping(false);  // activate continuous playing
boom.setPositional(false);   
boom.setVolume(3);
rootNode.attachChild(boom);
 //  boom.play();
}

/**
 *
 * @param tpf
 */

}