I have 2 cameras, one called “LeftCamera” and one called “RightCamera”. I made a script to toggle between the cameras, but I don’t like the way it looks. I need a script so that “LeftCamera” will change positions will ‘lerp’ when the input “SwitchShoulders” is pressed. Here are the camera positions:
LeftCamera Position:
X = -4177.642
Y = -3220.743
Z = 6346.121
RightCamera Position:
X = 5159.432
Y = -3220.743
Z = 5764.928
Put this on your camera. I’m sure you’ll need to edit it so it doesn’t toggle for every single key press.
public class TogglePosition : MonoBehaviour
{
public Vector3 leftPosition = new Vector3(-4177.642f, -3220.743f, 6346.121f);
public Vector3 rightPosition = new Vector3(5159.432f, -3220.743f, 5764.928f);
public float speed = 1000f;
void Update()
{
if (Input.anyKeyDown)
movingToRightPosition = !movingToRightPosition; // Go towards other position.
Vector3 targetPosition = movingToRightPosition ? rightPosition : leftPosition;
transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
}
bool movingToRightPosition;
}
Put this on your camera. I’m sure you’ll need to edit it so it doesn’t toggle for every single key press.
public class TogglePosition : MonoBehaviour
{
public Vector3 leftPosition = new Vector3(-4177.642f, -3220.743f, 6346.121f);
public Vector3 rightPosition = new Vector3(5159.432f, -3220.743f, 5764.928f);
public float speed = 1000f;
void Update()
{
if (Input.anyKeyDown)
movingToRightPosition = !movingToRightPosition; // Go towards other position.
Vector3 targetPosition = movingToRightPosition ? rightPosition : leftPosition;
transform.position = Vector3.MoveTowards(transform.position, targetPosition, speed * Time.deltaTime);
}
bool movingToRightPosition;
}
I tried the script and I got this compiler error. It’s probably simple, but I usually use JavaScript so I not really sure what’s wrong. Here’s the error