- Home /
Smooth gun movement?
How can I make my gun point in the same direction as my camera, but smoothly? I found this piece of code that works partly, but I need the variables to be constantly being set to the camera rotation. (The gun is a part of the camera)
var tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngleZ;
var tiltAroundX = Input.GetAxis("Vertical") * tiltAngleX;
var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613065633im_/https://answers.unity.com/themes/thub/images/avi.jpg)