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);
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter