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