- Home /
How to make an object rotate with the camera
I have a weapon and it have a laser. But the players will obviously note that the aim is "locked" in seconds. Do anyone know how to make an object rotate with the camera? ( I am using FPS Character)
Something that worked like: The player rotate the camera, and the laser rotate together. But i don't want it to blindly follow the camera, because it would glitch and all. I wanted something that would make the laser go ONLY some specific degress and then stop. I had a script that someone helped me to do that was similar, but i sincerely lost it =(
Did you tried making the laser GameObject as the child object of the camera?
I just figured out that i asked how to make an objecet rotate with the camera, and now i literally asked how to not.
Answer by orvedal · Sep 05, 2016 at 12:59 AM
Lerp the laser's rotation toward the the camera's rotation and it will smoothly rotate the gun to point in the direction you are "looking". This will appear as though you quickly moved your head to look somewhere and then pointed the gun there without looking like the gun is locked to the camera. As far as how you will do this, I would say to start with using RotateAround() to rotate the gun around the camera, otherwise if you use moveRotation() or just set the rotations equal to each other then gun will not point with the camera, rather it will just spin oddly in place without moving. It took some effort to actually understand rotation, and it is something you actually need to understand to do things the exact way you want them done. I suggest you use my post as a starting point and figure out how to use RotateAround() to rotate the laser around the camera and how to do it gradually using lerp or slerp interpolations to prevent the locked appearance. In my game I use the same method to prevent the locked appearance and this actually makes it feel more natural. Have a good day, Eric
Thanks! Amazing answer! :D
It's a great idea, i am going to work on this, it helped a lot.
Your answer
![](https://koobas.hobune.stream/wayback/20220612091939im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can i rotate object smooth without stop ? 2 Answers
player set to 0 on x-axis on play but in editor its set to -90 on x-axis 0 Answers
Why when using LookAt to make the turret facing the target it's facing the other direction ? 1 Answer
Rotate a Object, but with rotation values 2 Answers
Quaternion, eulerAngles, localEulerAngles Driving me mad 1 Answer