Question by
Stuarttheboy11 · Feb 09, 2020 at 07:11 PM ·
3rd person camera
How can I get my camera to follow my character on the y axis?
I'm new at c# so i don't really understand this. I'm trying to get my camera to follow my character/s when going up or down however i don't really know how to do that. Any suggestions or answers? here's my script.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ThirdPersonCam : MonoBehaviour {
public float mouseSensitivity = 10;
public Transform target;
public float dstFromTarget = 15;
public Vector3 pitchMinMax = new Vector3(-40, 85);
public float rotationSmoothTime = 0.12f;
Vector3 rotationSmoothVelocity;
Vector3 currentRotation;
float yaw;
float pitch;
void LateUpdate()
{
yaw += Input.GetAxis("Mouse X") * mouseSensitivity;
pitch -= Input.GetAxis("Mouse Y") * mouseSensitivity;
pitch = Mathf.Clamp(pitch, pitchMinMax.x, pitchMinMax.y);
currentRotation = Vector3.SmoothDamp(currentRotation, new Vector3(pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
transform.eulerAngles = currentRotation;
transform.position = target.position - transform.forward * dstFromTarget;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612223043im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to make a space ship fly after crosshair? 1 Answer
3rd person camera 0 Answers
Need help with a 3rd person Camera 0 Answers
How to Clamp a 3rd Person Camera's x-axis Rotation? 0 Answers
3rd person controller acting odd after hitting collider 0 Answers