2016-04-01 12 views
0

Ich habe ein 3D-Modell aus Asset Manager geladen und CharacterControl als Steuerelement hinzugefügt. Alles funktionierte einwandfrei, aber als ich versuchte das Modell zu drehen, funktionierte es nicht.Wie man eine räumliche Steuerung mit Physik in JmonkeyEngine3 dreht?

private CharacterControl player; 
private Spatial model; 
public static final Quaternion YAW045 = new Quaternion().fromAngleAxis(FastMath.PI/4, new Vector3f(0,1,0)); 

@Override 
public void simpleInitApp() { 

    // add bullet app sate to state manager 
    bulletAppState = new BulletAppState(); 
    stateManager.attach(bulletAppState); 
    bulletAppState.getPhysicsSpace().enableDebug(assetManager); 

this.addModel(); 
} 

private void addModel(){ 
    model = assetManager.loadModel("Models/Oto/Oto.mesh.j3o"); 
    model.setLocalTranslation(new Vector3f(0,10,0)); 

    capsuleShape = new CapsuleCollisionShape(1f, 7.9f, 1); 
    player = new CharacterControl(capsuleShape, 1f); 
    bulletAppState.getPhysicsSpace().add(player); 

    model.addControl(player); 
    rootNode.attachChild(model); 

    model.rotate(YAW045); 
} 

bitte helfen Sie mir.

+0

Wenn ich mich recht erinnere (es ist eine Weile her, seit ich etwas mit den Kontrollen getan habe) der Spieler die Kontrolle nun die Steuerung der Rotation, Position etc. Sie können es nicht auch manuell verschieben, da das Steuerelement es gerade zurück bewegt. Ich erwarte, dass die Charakterkontrolle eine Rotationsmethode hat, obwohl ich falsch liegen könnte –

Antwort

2

Richard hat Recht. Die Klasse CharacterControl hat eine setViewDirection() Methode. Sie sollten wirklich zu BetterCharacterControl wechseln, da es eine bessere Integration hat. Ich weiß nicht, warum CharacterControl nicht veraltet ist.

Im Allgemeinen haben Physikobjekte ein separates "Leben", da sie im Bullet PhysicsSpace leben. Zum Beispiel die andere allgemeine Physik-Kontrolle: RigidBodyControl Klasse hat eine setPhysicsRotation(Quaternion rotation) Methode (genau wie es eine setPhysicsLocation() Methode hat).

Weitere Informationen im Wiki (obwohl es CharacterControl verweist): Walking Character