Hi, I am confused how I can Lerp from inputDirection to targetInput when inputDirection has not yet been initialized, only defined. This piece of code is from a tutorial and I know it works, but I don’t know why. My guess is that inputDirection is a special type of Vector3 that is a reference to user input or that the default value for Vector3 is (0, 0, 0), but my research so far has been unsuccessful.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerMovement : MonoBehaviour
{
 private PlayerInputActions inputActions;
 private Vector2 movementInput;
 [SerializeField]
 private float moveSpeed = 10f;
 private Vector3 inputDirection;
 private Vector3 moveVector;
 private Quaternion currentRotation;
 void Awake()
 {
  inputActions = new PlayerInputActions();
  inputActions.Player.Movement.performed += context => movementInput = context.ReadValue<Vector2>();
  //Reads a Vector2 value from the action callback, stores it in the movementInput variable, and adds movementInput to the performed action event of the player
 }
 void FixedUpdate()
 {
  float h = movementInput.x;
  float v = movementInput.y;

  //y value in the middle
  //0 since no jump
  Vector3 targetInput = new Vector3(h, 0, v);
  inputDirection = Vector3.Lerp(inputDirection, targetInput, Time.deltaTime * 10f);
 }
}

I don’t see any indication that inputDirection is actually related to any user input.

Even if you don’t see it there, the inputDirection variable has an init value. So i suspect (like you did) that the vector3 default init from c# sets them all to 0. To test this, you can just declare a vector3 somewhere in your code and Debug.Log() it. It will print all values and if my guess is right, it should print (0,0,0).


EDITED

Vector3 is a struct and NOT a class, C# inits it to (0,0,0).