AI tries to hit with edge (scales with difficulty)

main
Benjamin Kraft 1 year ago
parent 7225357dc9
commit a0da50cd7e
  1. 15
      Assets/Scripts/Game/AIPlayer.cs
  2. 2
      Assets/Scripts/Game/GameManager.cs

@ -67,8 +67,9 @@ namespace Game {
}
private float IdlePosition => Difficulty >= Difficulty.Medium ? 0 : X();
private float DistortAmount => 1 - 1 / ((float) Difficulty + 1);
// TODO solution for balls outside of border
// TODO Also must include fact that players have a height, maybe check the incoming angle
// angle: 0 -> perpendicular, from -90 to 90
private bool IsPositionReachableInTime(float futurePosition, float seconds, float angle) {
@ -151,9 +152,13 @@ namespace Game {
float radius = ball.Radius;
float target = Simulate(origin, velocity, radius, FutureSeconds, 0, out bool impossible);
if (!impossible)
return target;
if (!impossible) {
float max = Width / 2;
float distortionOffset = DistortAmount * max;
distortionOffset *= target > X() ? -1 : 1;
return target + distortionOffset;
}
approaching.Remove(ball);
// This ball was impossible to catch, try next one
}
@ -163,7 +168,7 @@ namespace Game {
private float currentSmoothV;
private void ApproachPosition(float pos) {
float result = Mathf.SmoothDamp(X(), pos, ref currentSmoothV, .5f, Speed);
float result = Mathf.SmoothDamp(X(), pos, ref currentSmoothV, .2f, Speed);
transform.position = new Vector2(result, Y());
ClampInsideBorders();
}

@ -54,7 +54,7 @@ namespace Game {
private void Start() {
Settings.Type = Type.Hybrid;
Settings.AIDifficulty = Difficulty.Easy;
Settings.AIDifficulty = Difficulty.VeryEasy;
var ball = Instantiate(ballPrefab).GetComponent<Ball>();
Balls.Add(ball);

Loading…
Cancel
Save