Simple way of having a FPS-like gun on screen?

I’ve tried attaching it to the guiNode, but it doesn’t show. I’ve tried attaching it to the rootNode and applying the same rotation as the camera, but it’s always a bit off or completely wrong.



There should be a simple way to do that, that i’m sure i’ve missed?



I simply need a 3D mesh attached, like a gun in any FPS, that always stays in the same position no matter where the player looks. Hum, without using NiftyGUI if possible…

Hello!



No no no no, don’t attach it to the guiNode. :slight_smile:



Well, there are two ways that immediately come to mind. One is to attach it to the camera, camera node, or the player if your view/player is in fact something. Another would be to update the position/rotation of the gun based on the camera every frame. Obviously the first option is probably easier to work with, but I don’t know the situation you’re working with.



Even if the enemies see a floating gun of a player, the player will never know about it :stuck_out_tongue: Smoke and mirrors! :stuck_out_tongue:



Cheers!

~FlaH

Oh, so there is something like a camera node? I’ve browsed the source code for it, but couldn’t find it anywhere.



I’m using SimpleApplication, what is the name of the camera node? How do you “attach it to the camera” ?



I’ve tried updating position/rotation of the camera to the gun mesh, but it’s not working, it’s always a bit off.



Thanks a lot for the reply :wink:

I can give you code, if you like, but it’s really simple!



Create a node and call it whatever you like(“camera node”).

Go to your update method and get your camera position and rotation.

This values you apply to your Node(in the update method). Finished. Whatever you add to your camera node, will stay on your screen.

Well… here’s what i have:



playerNode.setLocalRotation( cam.getRotation() );



In the playerNode, there’s the player’s mesh and weapon. It works (although i have to apply a YAW180 rotation on each model) but when i look up or down, the weapon doesn’t follow 100%.



There’s no need for position update since the camera is never moved (nor the player).



If you have something different, please share :wink:

Ahhhh, never mind!!



The models are at 0,1,0 and the camera is at 0,3,0 hence the slight difference when looking up or down.



My bad, sorry…