protected bool CanReachPositionInTime(LocationPrediction slice) { var dist = Field.GetDist(Info.Location, slice.Location); var speed = dist / slice.DeltaTime; var currentSpeed = (float)Math.Sqrt((Math.Pow(Info.Velocity.X, 2) + Math.Pow(Info.Velocity.Y, 2))); return(speed < currentSpeed); }
protected LocationPrediction GetProjectedBall() { var predictions = BallPredictionService.GetPredictions(Ball, Field, Game); LocationPrediction target = null; foreach (var prediction in predictions) { if (CanReachPositionInTime(prediction)) { return(prediction); } target = prediction; } return(target); }
private static LocationPrediction GetPrediction(LocationPrediction ball, FieldService field, GameWrapper game, float deltaTime) { var prediction = new LocationPrediction(); prediction.DeltaTime = ball.DeltaTime + deltaTime; prediction.GameTime = game.TimeElapsed + deltaTime; prediction.Location = new Vec3(ball.Location.X, ball.Location.Y, ball.Location.Z); prediction.Velocity = new Vec3(ball.Velocity.X, ball.Velocity.Y, ball.Velocity.Z); var friction = prediction.Location.Z <= GameValuesService.BallRadius ? .6f : 1; // Apply forces prediction.Location.X += (ball.Velocity.X * deltaTime) * friction; prediction.Location.Y += (ball.Velocity.Y * deltaTime) * friction; prediction.Location.Z += (ball.Velocity.Z * deltaTime) - (GameValuesService.Gravity * deltaTime); if (prediction.Location.Z < GameValuesService.BallRadius) { prediction.Location.Z = GameValuesService.BallRadius; } return(prediction); }