public void UpdateControls() { var currentVelocity = gameObject.GetComponent <Rigidbody>().velocity; var pointToCheck = transform.position + currentVelocity * _lookAheadDistance; var closestPointOnRacingLine = _racingLine.FindClosest(pointToCheck); var heading = (pointToCheck - closestPointOnRacingLine); var varianceMag = heading.magnitude; //Determine if car is to the left or right of racing line Vector3 perp = Vector3.Cross(transform.forward, heading); float dir = Vector3.Dot(perp, transform.up); Debug.Log(dir); if (dir < 0) { _car.SetTurningPower(varianceMag); } else { _car.SetTurningPower(-varianceMag); } _car.SetAccelerationPower(1); _debugPointToCheck = pointToCheck; _debugClosestPoint = closestPointOnRacingLine; }