- Home /
third person camera
i was wondering how to make a third person camera with the ability to zoom in and out the main object, and rotate around it. but i would like to have a limit to how far it can zoom out. thanks! @Kilsnus
Answer by connorwforman · May 03, 2018 at 11:50 PM
one broblem both videos are the exact same neither show how to zoom
Answer by Guy_Yome · May 10, 2018 at 08:52 PM
Well okay, I already done that before so I can help you if it's not too late. You will have to get a reference of your camera in your player controller script. In the controller script, create a float that clamps and loop between 0 and 360 degrees. Now, when you move your mouse left or right, change the float variabe accoringly by increasing or decreasing. Then, every frame, convert that rotation into a Vector3. To do so, the x component of this vector will be Mathf.Cos(angle) and the z component will be Mathf.Sin(angle). To get a 2D system then add the y component depending on the players height. Take that Vector3 and do the_vector = the_vector.normalized so that its length is 1.
Part two : You will have to create 3 float variables. One is min_distance, another is max_distance and the other is actual_distance. You must clamp the actual distance in between these two (min and max). Now implement the code in which you increase and decrease the zoom by adding or substracting to the actual_distance variable (for now it's just a float). Then mulitply the previous Vector3 by the actual_distance. You now simply set the position of the camera from the player position + the_vector;
the_camera.transform.position = transform.position + the_vector;
The last thing to do after that is to make the camera look towards the player, which I'm sure you already have. So that's it. Good luck.