This is what I have:
public KeyCode k;
private Vector3 standing = new Vector3(0.0f, 0.9f, 0.0f);
private Vector3 sitting = new Vector3(0.0f, 0.4f, 0.0f);
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(k))
{
if (transform.localPosition.y > 0.5f)
{
transform.localPosition = Vector3.Lerp(standing, sitting, 3f * Time.deltaTime);
//transform.localPosition = sitting;
}
else
{
transform.localPosition = Vector3.Lerp(sitting, standing, 3f * Time.deltaTime);
//transform.localPosition = standing;
}
}
}
}
When I use the commented out lines “transform.localPosition = sitting”, this tiny script works to move the camera of the FPScharacter down as if sitting (and when the key is pressed, up again to standing).
When I try the Vector3.lerp version, it behaves erratically; pressing the key moves it down a little at a time, or up a little, or not at all.
What am I missing?