i tried to move the spatial
BUT!!
problem is that camera has a getDirection() method but a spatial doesnt have it !!
So even if we try to Translate it it wil just change its postiton
but the direction will not change:
HOW TO SOLVE THIS PROBLEM BY ANY MEANS
P.S please forgive my English
Camera also has getRotation, you can get its rotation with that method and apply it to spatial with setLocalRotation.
N.B. Camera.getRotation returns the rotation relative to world while Spatial.setLocalRotation sets the rotation relative to the spatial parent, so you may need to convert it depending of the structure of your scene.
Oh, yes you can absolutely use lookAt. I totally forgot this method.
For the conversion, assuming that you have c_wr that is your camera rotation and sp that is your spatial, you have to get the world rotation of sp.getParent() then you invert it and multiply for c_wr the resulting quaternion should be the local rotation that you have to apply to sp.
Not 100% sure about this though. Quaternions are still quite a mystery to me.
What About the Location @Xuan Problem is that as soon as i move my head towards other direction then the gun stays at its point
i think this is it BUT with a a bug
Depends on how you control your character. I use the BetterCharacterControl, so I need to update the camera position with the character’s world translation. But if your inputs affect the camera directly you’ll need to update the weapon’s node translation with the camera position (see aegroto’s post).
The thread you linked explains how to avoid having the gun disappear when you get too close to a wall, I recommend you to tackle the basic stuff first.