[SOLVED] Character model appears under level


#1

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);
                
    }

#2

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.


#3

model stand in normal place.

Capsule down under level physics.
and move slowly


#4
game.rootNode.attachChild(player.characterModel);
game.bulletAppState.getPhysicsSpace().add(player.characterControl);

Maybe scene and physics does not have time to load.


#5

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


#6

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


#7

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


#9

Normen how to make psychics and collision between players?


#10

I have no idea about psychics, sorry.


#12

It is not present in the engine at once?


#13

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


#14

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


#15

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


#16

Need to wait for application load:

  1. load model
  2. load physics

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


#17

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.


#18

solved server not send coordinates…