Why when using Input.GetKeyDown to switch between camera views i need to click few times to switch ?

using UnityEngine;

public class FollowTargetCamera : MonoBehaviour
{
    public Transform Target;
    public float PositionFolowForce = 5f;
    public float RotationFolowForce = 5f;
    public Vector3[] directions = new Vector3[] { Vector3.forward, Vector3.back
        , Vector3.left, Vector3.right };

    private int index = 0;
    private Vector3 vector = new Vector3(0, 0, 0);
    private Vector3 dir = new Vector3(0, 0, 0);



    void Start()
    {

    }

    void FixedUpdate()
    {
        if (Input.GetKeyDown(KeyCode.V))
        {
            if (++index == directions.Length)
                index = 0;
            vector = directions[index];
            dir = Target.rotation * directions[index];
        }
        dir.y = 0f;
        if (dir.magnitude > 0f) vector = dir / dir.magnitude;

        transform.position = Vector3.Lerp(transform.position, Target.position, PositionFolowForce * Time.deltaTime);
        transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(vector), RotationFolowForce * Time.deltaTime);
    }
}

Sometimes i click/press on the key V once or twice to move to the next view. Sometimes i need to click/press 3 times in a row to change a view. I want it to change a view each one click.

Move your code to “void Update ()” instead of FixedUpdate and see if that does it for you?

FixedUpdate should be used for physics calls exclusively.

1 Like

Thanks. Working.