public Transform target; // A variable that stores a reference to our Player
public Vector3 offset; // A variable that allows us to offset the position (x, y, z)
public float rotateSpeed = 5;
void Start()
{
offset = target.transform.position - transform.position;
}
void LateUpdate()
{
float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
target.transform.Rotate(0, horizontal, 0);
float desiredAngle = target.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler(0 ,desiredAngle, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt(target.transform);
}
}
Hello! So, I’ve been trying to make a third person shooter, and for that, I needed a camera that would work. So I got this code from a website (Unity3D: Third-Person Cameras) and decided to try it out. The camera seems to move along the x-axis when I move my mouse, so thats good, but the problem is, the camera keeps looking at the feet of my character, instead of forwards. I don’t really understand the code all that well so I couldn’t find a solution myself yet, so I was hoping to find some help here. I also can’t figure out how to get the camera closer to my character. So, if any of you could help me find a solution to both or either one of my problems, I would be very grateful. Also, please tell me if you need additional information. I also dont expect you to code anything, simple instructions are just as good.