How to retrieve spatial facing?

With a Geometry you can use lookAt(Vector3f position, Vector3f upVector) to change its heading so it points in a certain direction.



I’ve looked and looked but I couldn’t find a method to retrieve that facing. A bit of help here please would be much appreciated. Is there such a method? :slight_smile:

I’m afraid there is no simple way of doing this, and that if it’s doable, it involve some tricky math calculation.



@Momoko_fan could we store the looked at position and the up vector in a spatial or is that a bad idea?

I should have been clearer. What would be helpful, at least in my case, would be to retrieve the “currently looking at/currently facing direction”.



There could be other ways to get the facing, but if it could be easily be done by fetching a “getFacing” or whatnot, it would be best. But would it be demanding since it would involved a lot of calculation? What if, in my case, there are several ships? 5, 10, more?

Uh, just spatil.getWorldRotation().multLocal(Vector3f.UNIT_Z.clone()) ? This way the world rotation of the spatial will be applied on a vector and the resulting vector should be pointing in the z-direction of the spatial.

Cheers,

Normen

1 Like
normen said:
Uh, just spatil.getWorldRotation().multLocal(Vector3f.UNIT_Z.clone()) ? This way the world rotation of the spatial will be applied on a vector and the resulting vector should be pointing in the z-direction of the spatial.
Cheers,
Normen


Since a ship in my game travels (goes forward, turns, etc) independently of the rootNode's axis, meaning at one point I could travel toward -y or +z or +x, would that still work? I don't think it would.

If you use the world coordinates, yes. They include the parents rotation/location. If you only want the local direction, use getLocalRotation()

1 Like

I’ll take your word on it. I’ll test it out ASAP. I’ll get back to you! :slight_smile:



Thanks.

You can extract rotation column 2 from the spatial’s rotation quaternion, which corresponds to the direction the spatial is facing.

Forgot to say that what normen suggested worked. :slight_smile:



I can navigate on all 3D axis without a hitch.