Move model inside control

code:
characterModel = (Spatial)assetManager.loadModel("Models/player.j3o");
characterModel.move(new Vector3f(10.0f,10.0f,10.0f));

characterModel.addControl(player);
characterModel.setLocalTranslation(3.0f, 3.0f, 3.0f);

characterModel.rotate(5.0f, 5.0f, 5.0f);

rootNode.attachChild(characterModel);

How to move model inside control? Current code not work.

characterModel.setLocalTranslation(3.0f, 3.0f, 3.0f);

characterModel.rotate(5.0f, 5.0f, 5.0f);

I need down model. And move to center of capsule.

And how rotate model with mouse Z coordinates like counter strike? ( camera - vector, rotate - Degrees).

The code you supplied isn’t the code of the control (player?).

You must move/rotate it inside your control’s void controlUpdate(float) method in player. You have more information in the wiki.

inicialization

player = new PlayerControl(capsuleShape, 0.05f);

//player   = new PlayerControl(capsuleShape,0.05f);

player.setJumpSpeed(20);

player.setWalkDirection(walkDirection.mult(1f));

player.setFallSpeed(100);
player.setGravity(60);
//player.setPhysicsLocation(new Vector3f( 0.9f,  0.02f, 0.22f));


characterModel = (Spatial)assetManager.loadModel("Models/player.j3o");
characterModel.move(-10.0f, -10.0f, -10.0f);
characterModel.addControl(player);

player.setSpatial(characterModel);

rootNode.attachChild(characterModel);

Custom class

public class PlayerControl extends CharacterControl{

PlayerControl(CapsuleCollisionShape capsuleShape, float f) {
super(capsuleShape,f);
}

@Override
public void setSpatial(Spatial spatial) {
super.setSpatial(spatial);
}

@Override
public void update(float tpf){

if(spatial != null) {
    System.out.println("rotate");   
    spatial.rotate(0, 0, 1.0f);
}
super.update(tpf);

}
}

not work…

SetViewDirection or Wiki (Hello Physics)

Yes, wiki, wiki, wiki, wiki, wiki, wiki, wiki, wiki, wiki, wiki, wiki, wiki, wiki, wiki, wiki, wiki, wiki, wiki, wiki, wiki …
:wink:

And maybe better to start using JME 3.1 instead of 3.0. Especially if you are just starting out. It doesn’t fix this, but it sure as hell is nicer and newer :slight_smile:

Have this:

  float cX = player.getPhysicsLocation().x;
    float cY = player.getPhysicsLocation().y;
    float cZ = player.getPhysicsLocation().z;
    float mX = characterModel.getWorldTranslation().x;
    float mY = characterModel.getWorldTranslation().y;
    float mZ = characterModel.getWorldTranslation().z;
    float difX = cX - mX; 
    float difY = cY - mY; 
    float difZ = cZ - mZ; 
    characterModel.move(difX, difY- 2, difZ+2);

I think need write custom methods for synchronize capsule and model.

Again, please go through the tutorials. Everything is explained there. Just read and learn. This what you want to do is actually much easier to implement when you read the relevant wiki entries.

Thanks re-read manual. And next my “invention” :slight_smile:

      if(!camOld.equals(cam.getLeft())){
          camOld        = cam.getLeft(); 
         Quaternion camRotation = new Quaternion();
          
          camRotation.set(-0.173f, cam.getRotation().getY(), cam.getRotation().getZ(), 0.9830f);
          characterModel.setLocalRotation(camRotation); }

Any time you are calling set() on a Quaternion then you are probably doing something wrong.

Usually this is a sign of a barely noob Java developer who doesn’t know where the javadoc is. Hopefully you know where the javadoc is.

Yes, Thank’s http://jsockframework.blogspot.ru/2016/10/jsock-framework-doc-1.html
This is test code, i rewrite. Thank’s.