I have a camera that is looking at a player object at a 45 degree angle on a key press. As of now the rotation around the player works great.
The problem lies when I try to add a smooth camera follow at that 45 degree angle, because as the rotation changes, the follow coords change, and it gets a little wonky. Any of the typical camera follow methods I have used seems to have failed, I believe there is some fancy math work here that is beyond me,that or I’m overlooking something simple… Any help would be hugely appreciated!
Here is the code for the camera as of now:
public GameObject targetObject;
private float targetAngle = 0;
const float rotationAmount = 1.5f;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Q))
{
targetAngle -= 90.0f;
}
else if (Input.GetKeyDown(KeyCode.E))
{
targetAngle += 90.0f;
}
if (targetAngle != 0)
{
Rotate();
}
}
protected void Rotate()
{
if (targetAngle > 0)
{
transform.RotateAround(targetObject.transform.position, Vector3.up, -rotationAmount);
targetAngle -= rotationAmount;
}
else if (targetAngle < 0)
{
transform.RotateAround(targetObject.transform.position, Vector3.up, rotationAmount);
targetAngle += rotationAmount;
}
}