Object direction


i am new to JME (actually my second day…) and have some problem with setting object's direction. I want it to face the direction it follows. This code randomly makes a path for the object. I tried to set the objects face to the direction with lookat, but it doesnt really work (i dont see any change, it looks always to the same direction):

            st.setPosition(0, 0, new Vector3f(x,y,z));

            float f = r.nextFloat();


            f = r.nextFloat();


            f = r.nextFloat();


            st.setPosition(0, 1, new Vector3f(xa,ya,za));

            modell.lookAt(new Vector3f(xa,ya,za), new Vector3f(0,1,0));





I think i dont use the lookat correctly. Can you advise? Thanks.

the way u use look at method is fine.

but did u update ur geometric state after that?

No, i dont think i have…how can i do that?

gombasp said:

No, i dont think i have...how can i do that?

what game implementation r u using? basegame, standardgame, simplegame?

and btw another thing i just thought of.

when u use model.lookAt(), make sure the vector3f u passed in its in world coordinates.

if u want to use a normalized direction unit vector, use model.getlocalRotation.lookAt();

I tried to add modell.updateGeometricState(0,true). Now the modell is far away from my viewpoint but still facing wrong direction (but why is it that far?)

Then i tired

modell.getLocalRotation().lookAt(new Vector3f(xa,ya,za), new Vector3f(0,1,0));

This is also not the working…

I use simple game and loaded a 3ds modell. I understand that 3ds has a different coordinate system - but it seems that its not changing its face to movement direction at all.

st.interpolateMissing(); indicates that you are using a SpatialTransformer to animate your model. So you should probably not rotate it directly, since the SpatialTransformer will override the rotation you set. You might have to compute the rotation quaternion yourself (look at Spatial.lookAt() to see how to do that), and set it in the SpatialTransformer. Or, you could just drop the SpatialTransformer altogether, and set location and rotation of your model all by yourself. Finally, you can wrap your model into a Node, which is transformed by the SpatialTransformer, and set the rotation on the model itself.

oh~spatialTransformer again :smiley:

sry i didnt c that, and what hevee said can be very true.

spatialTransformer is a very…lets say annoying, at least its annoying to me~

it overrides any changes u made right after updateGeometricState().

i would strongly recommand not use it, but write ur own move/rotate method.