Hi! I have a cube that moves, i have a camera follow script that follows that cube. That is.
public class CameraFollow : MonoBehaviour
{
public Transform target;
public float smoothSpeed = 0.125f;
public float rotationAngleY = 90f;
public float rotationSpeed = 10f;
public Vector3 offset;
private void FixedUpdate()
{
Vector3 desiredPosition = target.position + offset;
transform.position = desiredPosition;
Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
transform.position = smoothedPosition + offset;
}
I need to rotate camera around this cube by pressing button on 90 degrees, i did that, but camera rotates around itself, not a target. But when i comment the cameraFollow part of script, it works correctly
private float targetAngle = 0;
const float rotationAmount = 1.5f;
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
targetAngle += 90.0f;
}
if (targetAngle != 0)
{
Rotate();
}
}
private void Rotate()
{
if (targetAngle > 0)
{
transform.RotateAround(target.position, Vector3.up, -rotationAmount);
targetAngle -= rotationAmount;
}
}
Will be pleausure for any help, stuck on this for a day.