[SOLVED] Character model appears under level

Some times model appears at normal place
Some times model appears under level

Code:
public void simpleInitApp() {

    //cam.set   
    camOld = cam.getLeft();  
    
    /** Set up Physics */
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    //bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    
    
    // We re-use the flyby camera for rotation, while positioning is handled by physics
    viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
    flyCam.setMoveSpeed(0.2f);
    
    
    setUpKeys();
    setUpLight();

    
    // We load the scene from the zip file and adjust its size.
    //assetManager.registerLocator("Models/" + levelName + ".zip", ZipLocator.class);
   // sceneModel = assetManager.loadModel(levelName+".scene");
    
   
    sceneModel = assetManager.loadModel("Models/" + levelName + "/" + levelName + ".scene");
    
    
    sceneModel.setLocalScale(2f);

    // We set up collision detection for the scene by creating a
    // compound collision shape and a static RigidBodyControl with mass zero.
    com.jme3.bullet.collision.shapes.CollisionShape sceneShape =
            CollisionShapeFactory.createMeshShape(sceneModel);
    
    landscape = new RigidBodyControl(sceneShape, 0);
    sceneModel.addControl(landscape);

    rootNode.attachChild(sceneModel);
    
    //get Start position
    
    bulletAppState.getPhysicsSpace().add(landscape);

    state = "sync";
    
    synchronization();
    
    //rootNode.attachChild(characterModel);
   // bulletAppState.getPhysicsSpace().add(player);
   
   
  }

add player

public static void addPlayerUpdate(final JSONObject playerJson,final String key){
         final GameLevel game = GameLevel.getInstance();
         
         game.enqueue(new Callable<Void>() {
            public Void call() throws Exception {

                Player player          = new Player();
                player.assetManager    = instance.assetManager;

                player.camLeft         = instance.camLeft;

                player.id              = key;
                
                if(player.id.equals(JConfig.user_id)){
                   player.isLocal = true;
                }
                
                player.setJsonKeys(playerJson);

                
                player.levelId         = instance.levelId;


               // player.startLocation = gameLevel.startPosition.get(player.slot);


                player.init();

                //System.out.print("add player " + player.id);

                game.players.put(player.id, player);


                game.rootNode.attachChild(player.characterModel);
                game.bulletAppState.getPhysicsSpace().add(player.characterControl);
              
                
                return null;
            }
        });
    }

  /**
     * Init model
     */
    public void init() {
        
        //
        // We set up collision detection for the player by creating
        // a capsule collision shape and a CharacterControl.
        // The CharacterControl offers extra settings for
        // size, stepheight, jumping, falling, and gravity.
        // We also put the player in its starting position.
        capsuleShape     = new CapsuleCollisionShape(1.4f, 3f, 1);

        //capsuleShape.
        characterControl = new PlayerControl(capsuleShape, 0.05f);

        characterControl.setJumpSpeed(20);

        characterControl.setFallSpeed(100);
        characterControl.setGravity(60);

        // characterControl.setPhysicsLocation(new Vector3f( 0.9f,  0.02f, 0.22f));

        characterModel = (Node) assetManager.loadModel(modelPath);

        moveSpatial = characterModel.getChild("base.obj");
        
        
        
        characterModel.move(0.050779365f, -1.74886445f, 12.0f);

        characterModel.rotate(12.0f, 0.0f, 0.0f);

        
        moveSpatial.setLocalTranslation(new Vector3f(0, -0.2f, 0));

        AnimListener rotateListener = new AnimListener();
        AnimListener runListener = new AnimListener();

        rotateControl = characterModel.getChild("base.obj").getControl(AnimControl.class);

        rotateControl.addListener(rotateListener);

        rotateChannel = rotateControl.createChannel();
        
        

        runControl    = characterModel.getChild("base.obj").getControl(AnimControl.class);

        runControl.addListener(runListener);

        runChannel    = runControl.createChannel();

        characterControl.setPhysicsLocation(startLocation);
        
        
        //rotateChannel.setAnim("direct-left");
        runChannel.setAnim("run");
        runChannel.setSpeed(0);
        runChannel.setLoopMode(LoopMode.Loop);

        
        rotateChannel.setAnim("direct");
        rotateChannel.setSpeed(0);
        rotateChannel.setLoopMode(LoopMode.DontLoop);
                
    }
1 Like

Sorry, but in my opinion your code is a little messed up and not really readable for us.

However, could you please elaborate your issue a little bit. What do you mean by “under level”? Is the player falling down, stuck he somewhere, or what?

I once had an similar issue, though. I solved it by creating all the physics (shapes) first and then when the whole scene is initialized I add the player to the scene / add it to BulletAppState.

1 Like

model stand in normal place.

Capsule down under level physics.
and move slowly

1 Like
game.rootNode.attachChild(player.characterModel);
game.bulletAppState.getPhysicsSpace().add(player.characterControl);

Maybe scene and physics does not have time to load.

1 Like

You have time delay between load level, psychics and load character?

1 Like

You can try physics debug mode to see if there is something wrong with your setup.

1 Like

By the way adding newlines doesn’t make code more readable, removing them does :slight_smile:

2 Likes

Normen how to make psychics and collision between players?

1 Like

I have no idea about psychics, sorry.

3 Likes

It is not present in the engine at once?

1 Like

There are no psychics in the engine that I know of.

3 Likes

I think need check collision and if next move - “collision” - not move…

1 Like

Game level have physics.
If player collision with game level - he stop.
But why if player collision with player - he not stop.

1 Like

Need to wait for application load:

  1. load model
  2. load physics

Application or bulletAppState have method for check “state”: init load etc?

1 Like

here is example of physics implementation using zay-es and bullet.
sources are there so you can investigate that.

there is also Paul’s mphys project demo. it is some where within jme hub. with sources.
you can investigate that also.

there beginner tutorial series, where physics and it’s debugging is described.
that also can be investigated.

there is ThinMatrix youtube tutorial series, with his engine and his initial physics implementation. there is no sources, but it can be written by your moving through.

any of these can be investigated / debugged / integrated.

1 Like

solved server not send coordinates…

2 Likes