private List <AITunnel> GetNextTunnels(Vector3 PlayerPosition, AITunnel CurrentTunnel) { List <AITunnel> ListNextTunnel = new List <AITunnel>(); List <AITunnel> ListPassedTunnel = new List <AITunnel>(); List <AITunnel> ListOtherTunnel = new List <AITunnel>(); float PlayerPositionInTunnel = Vector3.Dot(CurrentTunnel.Forward, PlayerPosition); foreach (AITunnel NextAITunnel in CurrentTunnel.ListNextAITunnel) { float Min, Max; NextAITunnel.GetEntryPoints(CurrentTunnel.Forward, out Min, out Max); //Tunnel is in front of the player if (Min > PlayerPositionInTunnel && Max > PlayerPositionInTunnel) { ListNextTunnel.Add(NextAITunnel); } //Tunnel is behind of the player else if (Min < PlayerPositionInTunnel && Max < PlayerPositionInTunnel) { ListPassedTunnel.Add(NextAITunnel); } else { ListOtherTunnel.Add(NextAITunnel); } } if (ListNextTunnel.Count > 0) { return(ListNextTunnel); } else if (ListOtherTunnel.Count > 0) { return(ListOtherTunnel); } else { return(ListPassedTunnel); } }
public void TestTunnelChangePrediction() {//Only change direction if the vehicule will exit the next tunnel by going straight AITunnel NextTunnel = new AITunnel(); NextTunnel.Rotate((float)-1.3258176636680326f, 0, 0); NextTunnel.Position += new Vector3(0, 0, -210); NextTunnel.Scale(new Vector3(10, 1f, 1f)); Vehicule ActiveVehicule = Vehicule3D.GetUnitTestVehicule(new Vector3(0f, 0f, 0f)); bool NeedToTurnRight; TunnelChangePredictionResults Prediction = ActiveVehicule.GetTunnelChangePrediction(NextTunnel, out NeedToTurnRight); if (Prediction == TunnelChangePredictionResults.Overshoot)//Check if you would be braking too soon and end up undershooting instead. { float ExpectedTimeToStop; } else if (Prediction == TunnelChangePredictionResults.Undershoot || Prediction == TunnelChangePredictionResults.Aligned)//Keep going { } }