I’m using the MouseOrbitImproved script and it more or less does what I want it to do but I need help implementing one more thing.
When the player runs to the right or left, I would like the camera to follow him around in a circle, similar to in most platform games.
What’s the best way to achieve this? Here’s the Mouse Orbit code
void LateUpdate()
{
if (target)
{
x += Input.GetAxis("Mouse X") * xSpeed * distance * 0.02f;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
y = ClampAngle(y, yMinLimit, yMaxLimit);
RaycastHit hit;
if (Physics.Linecast(target.position, transform.position, out hit))
{
distance -= hit.distance;
}
distance = Mathf.Clamp(distance - Input.GetAxis("Mouse Y") * 0.1f, distanceMin, distanceMax);
Quaternion rotation = Quaternion.Euler(y, x, 0);
Vector3 negDistance = new Vector3(0.0f, 0.0f, -distance);
Vector3 position = rotation * negDistance + target.position;
transform.rotation = rotation;
transform.position = position;
}
}