[SOLVED] Calculation of shot direction

Hello everybody,



I have a player's figure which should shoot along its line of sight. It is a third person game, so I cannot take the line of sight of the camera for this task.



I thought about taking the local rotation of the figure and a vector representing the initial line of sight. Then, I want to rotate this vector with help of the rotation quaternion to get the current line of sight.



So I came that far:


Quaternion quat = vehicle.getLocalRotation();
Vector3f initDirection = new Vector3f(1,0,0);



Then I noticed, that Vector3f has no "setLocalRotation()" (or something else)  :'(
I think I have to use values of Quaternion#toAngles() or similar to calculate the current line of sight. But I have no real idea how to do this properly. Can anyone help me?

I didn’t understand what you exactly want to do.

Do you want to just fire into the direction the player is heading?



player.getLocalRotation().getRotatinColumn(2) gives you the direction the player is heading currently as a Vector3f.



In Stardust my enemies have a simple view range of 45

To do what you are talking about with transforming a given Vector according to where your node is facing, you would use vehicle.localToWorld(initDirection, store).



Core-Dump's method of using getRotationColumn is easier though, if you just need one of the axes.

Just to clarify, what you need to do is multiply the world rotation quaternion and the initial vector. That operation provides a new vector which the vector you look for:


Vector3f shotDirection = n.getWorldRotation().mult(Vector3f.UNIT_Z);



Core's method does actually the same and is faster. But that multiplication is "the idea behind".

Thank you very much for your replies - I learned a lot again!  :smiley:



Core's player.getLocalRotation().getRotatinColumn(2) worked fine for me, but I needed to set the parameter to 0 instead of 2.