Hi, I’m making a third-person space game where the player jumps on planets and orients itself in full 3D space. I have a camera that is a child object of the player, positioned some distance back and can look up and down based on mouse Y input. However, it works as a first-person camera so when the player moves the camera up or down, the player is not visible anymore. What I want and what I’m trying to do instead is to have the camera always orient itself to look at the player and move in this locked spherical movement only around the Y-axis around the player.
This is the code that I have now, but it just doesn’t seem to work properly. As the camera only barely moves around in the general direction but doesn’t keep up with the player.
Code attached to the player:
void Update()
{
//Get Mouse movement Y and turn it into float, also rotates the player on the X axis
transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * Time.deltaTime * mouseSensitivityX);
verticalLookRotation += Input.GetAxis("Mouse Y") * Time.deltaTime * mouseSensitivityY;
verticalLookRotation = Mathf.Clamp(verticalLookRotation, -180f, 180f);
//I'm really not sure of this rotation Quaternion and I feel like this is the major problem
Quaternion rotation = Quaternion.Euler(verticalLookRotation, transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.z);
Vector3 negDistance = new Vector3(0.0f, 0.0f, -15f);
Vector3 position = rotation * negDistance + transform.position;
cameraT.position = position;
cameraT.localEulerAngles = Vector3.left * verticalLookRotation;
}
And an image I made in the powerful MSPaint of what I need: