Node lookAt doesn't work when I use RigidBodyControl?

Hello all, my lookAt doesn’t work in my code and I don’t understand why :frowning: :



[java]public class Ghoul extends character implements AnimEventListener {

private Node model;

private AnimChannel animChannel;

private AnimControl animControl;

private float linearDamping = .75f;

private RigidBodyControl control;

private Node ghoul = new Node();



public Ghoul(int id){

Material skin = new Material(var.app.getAssetManager(), “Common/MatDefs/Light/Lighting.j3md”);

skin.setTexture(“DiffuseMap”, var.app.getAssetManager().loadTexture(new String(“ressources/ghoul/diffuse.png”)));

skin.setTexture(“NormalMap”, var.app.getAssetManager().loadTexture(“ressources/ghoul/normal.png”));

skin.setTexture(“SpecularMap”, var.app.getAssetManager().loadTexture(“ressources/ghoul/specular.png”));



model = (Node)var.app.getAssetManager().loadModel(“ressources/ghoul/ghoul.mesh.xml”);

model.setMaterial(skin);

model.setName(Integer.toString(id));

ghoul.setName(Integer.toString(id));



animControl = model.getControl(AnimControl.class);

animChannel = animControl.createChannel();

animControl.addListener(this);

animChannel.setAnim(“idle”);



model.setLocalScale(2.5f);

ghoul.attachChild(model);

var.pnjs.attachChild(ghoul);



model.setShadowMode(ShadowMode.CastAndReceive);

ghoul.setShadowMode(ShadowMode.CastAndReceive);



control = new RigidBodyControl(CollisionShapeFactory.createDynamicMeshShape(model), 100f);

model.addControl(control);



var.app.getPhysicsSpace().add(control);

control.setAngularFactor(0);

control.setLinearDamping(linearDamping);

control.setPhysicsLocation(new Vector3f(-140, 40, -10));



}



public void update(float tpf) {

ghoul.setLocalTranslation(control.getPhysicsLocation());

Vector3f look = var.MyPlayer.getPhysicsLocation().clone();

look.setY(control.getPhysicsLocation().getY());

ghoul.lookAt(look, Vector3f.UNIT_Y);

}



}[/java]



What is the problems please ?



PS: Sorry for my bad english :confused:

Read the tutorials, you have to move the phsics control, not the spatial.

1 Like

Thank you, now I try it:

[java]

Vector3f look = var.MyPlayer.getPhysicsLocation().clone();



look.setY(control.getPhysicsLocation().getY());



float angle = look.angleBetween(control.getPhysicsLocation());



control.setPhysicsRotation(control.getPhysicsRotation().fromAngleAxis(angle, Vector3f.UNIT_Y));[/java]



But it doesn’t work :frowning: , why ?

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies

Oh yes sorry that was a stupid error :confused:

Ok now, i really don’t understand the problem -_-" :



[java]Vector3f look = var.MyPlayer.getPhysicsLocation().clone();



look.setY(control.getPhysicsLocation().getY());

Quaternion q = new Quaternion();

q.lookAt(var.control.getPhysicsLocation(), Vector3f.UNIT_Y);

control.setPhysicsRotation(q);[/java]



Sorry but rotation is not easy for me (like other things :X)

Nobody want help me ? I know it’s probably a stupid error, but I can’t find it…

Please don’t bump your post within less than 10 hours :roll: What did you do to solve your problem in the meantime? Did you actually read the link I gave you?

Yes and now i creat a quaternion and I made a lookAt with it, after i set the phisycs rotation by the quaternion, but my ghoul rotate only one time…



Sorry for the bump :confused:

Probably because the location of the target doesn’t change. lookAt on a quaternion works differently, you have to subtract the ship location. Its all being said in the tutorial.

Ok, thank you for your help, I have found an other way and it works fine :slight_smile: