- Home /
How do I stop my FirstPersonController weapon from moving away from the camera position when I look up and down?
Hi,
I am new to Unity and making my first FPS.
I am trying to attach my weapon to the camera so it moves around with me.
I have attached the weapon to the FirstPersonController Main Camera and positioned it so it appears on screen correctly.
The weapon follows me around the map fine and goes wherever I do, all is fine until I move the camera up or down, the gun ends up moving away from the camera the higher/lower I aim. Looking at it in the scene view, the gun moves above the position of the camera when looking up and below it when looking down (when camera is in default position and looking left and right it is fine).
I did the exact same procedure in v2.6 and it worked absolutely fine, but doing it in 3.3 (that I have just started using) I am having this problem.
It does not appear to be a problem with the weapon itself as I tried using a GameObject>Cube as a test gun and the exact same thing happened with that.
I have tried attaching the gun directly to the camera and also attaching it to an emptyGameObject and attaching that directly to the camera instead, but the same thing happens either way.
I have attached 2 screenshots, the first showing the gun appearing correctly in its default position and the second showing the gun going above the camera when looking upwards.
Any help would be greatly appreciated and I thank you in advance.
James
Answer by flaviusxvii · Jun 15, 2011 at 06:04 PM
My guess is that your gun model isn't centered around the origin of its local coordinate space. So when you rotate it is rotating correctly, because the gun itself is shifted in it's space.
You can check by making a cube and making another copy of the gun and putting them both at (some location.. call it 10, 10, 10).. then go see if they line up the way you'd expect.
Answer by CHU · Jun 15, 2011 at 11:06 PM
Thanks for the advice, I think you are right, I must have moved something at some point, as when I deleted the FirstPersonController and the gun and put them back in again everything worked fine again!
Thanks again.
Your answer
Follow this Question
Related Questions
HDRP Camera weapon layer 1 Answer
First person camera restriction. 1 Answer
Camera on Body going crazy 1 Answer
Camera X and Y velocity HELP! 0 Answers
Blender animation walk in unity 1 Answer