private void JoinLaneIfSafe(Vector3 direction) { // Debug.Log("Current speed is " + vehicle.GetCurrentSpeed() + ", ideal speed " + idealLaneMergingSpeed.ToString()); if (ReachedDestinationLane()) { // Debug.Log("Reached destination lane"); CurrentLane = GetDesiredLane(); CurrentState = DrivingAgentState.Driving; return; } if (IsDesiredLaneFreeOfObstacles()) { Debug.Log("Lane is free. Steering towards it..."); Vector3 dir = (GetLaneAdjustedTarget() - gameObject.transform.position).normalized; float currentSteeringAngle = Vector3.Dot(dir, transform.forward); // Steer towards lane. direction = TrafficDirection == Vector3.left ? direction : -direction; if (direction == Vector3.left && currentSteeringAngle > 1 - LaneMergingMaxSteeringAngle) { vehicle.SteerLeft(); } else if (direction == Vector3.right && currentSteeringAngle > 1 - LaneMergingMaxSteeringAngle) { vehicle.SteerRight(); } } }
private int GetChangeInLaneInt(DrivingAgentState state) { switch (state) { case DrivingAgentState.JoiningInternalLane: return(-1); case DrivingAgentState.JoiningExternalLane: return(1); default: return(0); } }