// After leaving the park, car turns onto path private void AlignWithPath() { // Gradually move forward and turn until a degree of rotation is achieved if (degreesOfRotation < 90) { transform.Rotate(Vector3.up, PARK_ROTATION_SPEED * Time.deltaTime); transform.position += transform.rotation * forwardVector * Time.deltaTime; degreesOfRotation += PARK_ROTATION_SPEED * Time.deltaTime; } else { leavingState = CarLeavingState.AUTO; } }
// Car reverses and turns to pull out of a car park private void ReverseAndTurnOutOfPark() { // Gradually reverse and turn until a degree of rotation is achieved if (degreesOfRotation < 60) { transform.Rotate(Vector3.up, PARK_ROTATION_SPEED * Time.deltaTime); transform.position += transform.rotation * reverseVector * Time.deltaTime; degreesOfRotation += PARK_ROTATION_SPEED * Time.deltaTime; } else { leavingState = CarLeavingState.FORWARD_TURN; } }
// Car moves backward out of a car park private void ReverseOutOfPark() { Ray rayBehind = new Ray(transform.position + Vector3.up, transform.rotation * Vector3.back * STOP_BACK_DISTANCE); Debug.DrawRay(transform.position + Vector3.up, transform.rotation * Vector3.back * STOP_BACK_DISTANCE, Color.red, 0.5f); bool allOtherCarsWaiting = true; isWaiting = CheckGiveway(rayBehind, ref allOtherCarsWaiting, STOP_BACK_DISTANCE); if (!isWaiting) { // Reverse a fixed distance to a location if (distanceReversed < REVERSE_DISTANCE) { transform.position += transform.rotation * reverseVector * Time.deltaTime; distanceReversed += reverseVector.magnitude * Time.deltaTime; } else { leavingState = CarLeavingState.REVERSE_TURN; } } }