- Home /
Fixed-Position Camera that follows player,Fixed Position Camera that follows target.
Hello. I want to make a camera that stays in a fixed position but follows the target as the focus point, kind of like a security camera that can turn. I think it is updating the camera's transform.rotation but not sure what to set the quaternion to, or if I should be doing something similar to a raycast vector as an input for something.
Ideally, the outcome I want is the camera to be in the center of the room, above like from the ceiling, looking down and following the player around the square-ish room. I would also prefer if only the X and Y rotational axes move, with Z remaining locked at 0. Basically a fixed position camera that can swivel around to follow the player, but not rotate in the Z axis.
Thank you for any help you can offer.,Hello. I want to make a camera that stays in a fixed position but follows the target as the focus point, kind of like a security camera that can turn. I think it is updating the camera's transform.rotation but not sure what to set the quaternion to, or if I should be doing something similar to a raycast vector as an input for something.
Ideally the outcome I want is the camera to be in the center of the room, above like from the ceiling, looking down and following the player around the square-ish room. I would also prefer if only the X and Y rotational axes move, with Z remaining locked at 0. Basically a fixed position camera that can swivel around to follow the player, but not rotate in the Z axis.
Thank you for any help you can offer.
Answer by davidcox70 · May 04, 2018 at 02:59 PM
Use Transform.LookAt, like this: https://docs.unity3d.com/ScriptReference/Transform.LookAt.html
This is definitely what I was looking for and gives a great start, thank you! Now I just need to tweak the proportions and other things. Thank you @davidcox70 and @Tespy
What would be the best way to scale the movement? I don't need the camera to follow exactly to where the player but I just want it to turn in the direction. So if the player moves all the way to the north end of a room, I want the camera to just rotate like maybe 50% of the way northward. I tried making a new transform with position = (player.position - transform.position) / 2 but that didn't do anything, which I think is because I don't know how to initialize the new transform.
There is also a slightly different function called RotateTowards. LookAt will jump directly to face whatever the target is. RotateTowards will slowly rotate until it faces the target, so a more human feel.
https://docs.unity3d.com/ScriptReference/Vector3.RotateTowards.html
In terms of rotating part way, I have actually answered that very question recently. I'll see if I can find it so I can post a link....
Answer by Tespy · May 04, 2018 at 03:04 PM
I think the LookatTarget script in Unity's built-in packages should do the trick. You may need to mess around with the rotation ranges and follow speeds to get exactly what you want, but you don't need to code anything special yourself.
In Unity, right-click your Assets folder, go to Import Package, then click Cameras. Wait for the package to load. In the import menu, click Import. Wait for the process to finish, and there you go!
Thank you. When I right click the Assets folder and go to Import Package, my only option is Custom Package with the browse window. Where would the camera package be located?
Your answer
Follow this Question
Related Questions
How to achieve a 3rd person camera for walk on planet games? 0 Answers
make a target camera? 1 Answer
Make camera follow player and align direction 0 Answers
How can camera smoothly follow a jerky game object? (bouncing up and down) 1 Answer
How can i make the camera look up and down through keyboard keys? 2 Answers