Fixed Camera rotate to follow player
I am trying to have a camera in a fixed position rotate to follow the player (capsule) as he moves around on this platform. The player can freely move in any direction, but I don't want the camera to try to maintain a constant distance. I want its x and z position fixed. I'd also like the camera to follow the player's y position, so it will follow the player up and down as it, for example, jumps or climbs stairs.
I've been looking and experimenting to get this to work in C#, but I'm not sure how. Any help would be appreciated.
Answer by Lost-Echo · Feb 16, 2018 at 09:52 PM
I have a very similar problem, I have to be able to set the camera at 0,0,0 and have it rotate to follow the player from a considerable distance. If i come up with something I'll try to share it.
I found this on the script reference page, it gets the ball rolling at least, plug in the code into the camera and set it to your player, I just need to figure out how to get it to zoom in..
https://docs.unity3d.com/ScriptReference/Transform.LookAt.html
Answer by OIdamoh · Feb 17, 2018 at 04:30 PM
Hey,
I don't know if i understand you correctly, but how about this approach.
Attach a Script to the camera-gameoject. In Awake/Start grab a reference to the Player (or drag n drop the player to the Script in Editor when the player is not instantiated). Calculate the difference in YPos between Player and Camera.
In the Update-Function of the Cam-Script you can change the Rotation per Lookat and adjust the y-Pos of the Camera accoording to the difference you Initially saved and the current position of the player.
Hope it helped
Your answer
Follow this Question
Related Questions
Camera rotation problem 0 Answers
Spyro Like Camera Follow 0 Answers
C# Smooth Follow Space Ship 1 Answer
When attaching my custom camera script camera shakes when player starts to move fast. 1 Answer