- Home /
Rotation/position question.
So I am making a script to stick my gun to the players screen, however, for some reason there is a delay when I look around (like in battlefield 3/planetside 2). I don't want this to happen and it is causing my gun to jitter. I can't figure out what is wrong. This script runs in the gun.
transform.position = cameraObject.transform.position;
rotationTarget = cameraObject.transform.rotation;
transform.rotation = rotationTarget;
Why don't you just make the gun a child of the camera in the hierarchy?
Because I have code that drops it as well as some others and I don't know how I would have to rework it to make it work. Thing is that I had it work and now it's not working :\
Answer by nsxdavid · Mar 10, 2013 at 03:34 AM
Do either:
Make the gun a child of the camera (as suggested above)
If your movement is done in physics and/or FixedUpdate(), then gun placement should as well.
Check your script order execution. Consider gun placement in LateUpdate() instead of Update()
It's already in a LateUpdate() and look at my comment above.
Woo! what a snarky reply to a good answer. Dendens, don't take the easy way out of coding something just because you don't know how to do it the right way. It probably sounds silly, but you're just cheating yourself. Good answer, nsxdavid.
It wasn't a snarky reply. All I said is that in my situation his solution would not work with my other code. Anyways I just found out that I can parent and unparent through code so I actually am going to try it. When I am done I'll message back.
Ok, sorry then -- hard to tell people's tones. Oh, yes! Parenting and unparenting through code. Good call.
Ok, so parenting and unparenting through the code worked, thanks! :D
Your answer
Follow this Question
Related Questions
Gun not rotating with the camera? 1 Answer
Transform rotation 2 Answers
gun rotation fps 0 Answers
Aiming down a gun 4 Answers
why wont machine gun follow first person controller 2 Answers