Unity lerp lane to lane

PHOTO EMBED

Mon Mar 08 2021 13:45:39 GMT+0000 (UTC)

Saved by @cotterdev #c#

private void FixedUpdate()
{
  Vector3 _leftRightLaneChange = new Vector3(0.0f, 0.0f, 0.0f);

  if (_leftturn)
  {
    //Keep lerping left until we reach x
    if (transform.position.z > (_laneCoordinate[_myLanePos] - .05f))
    {
      _leftturn = false;
    }
    else
    {
      //** Calculate Lane Change **                                     
      float _diffTargetLanePos = _laneCoordinate[_myLanePos] - transform.position.z;
      float _changeThisAmount = Mathf.Lerp(_diffTargetLanePos, 0.0f, _laneChangeLerpVal);
      _leftRightLaneChange = new Vector3(0.0f, 0.0f, _changeThisAmount);
    }            
  }

  // Move
  _rb.MovePosition(transform.position + transform.forward * Time.fixedDeltaTime * _speed + _leftRightLaneChange);
}
content_copyCOPY