from medium upwards, ai goes to middle when idle

main
Benjamin Kraft 1 year ago
parent f109ffbd34
commit b9c07db9d0
  1. 21
      Assets/Prefabs/Player.prefab
  2. 5
      Assets/Scripts/Game/AIPlayer.cs
  3. 5
      Assets/Scripts/Game/GameManager.cs

@ -13,7 +13,6 @@ GameObject:
- component: {fileID: 5402279313309450412}
- component: {fileID: 1666507220592599477}
- component: {fileID: 1287955657}
- component: {fileID: 6551590900950860653}
m_Layer: 0
m_Name: Player
m_TagString: Untagged
@ -30,7 +29,7 @@ Transform:
m_GameObject: {fileID: 5402279313309450415}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 4, y: 4, z: 4}
m_LocalScale: {x: 4, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
@ -121,7 +120,7 @@ PolygonCollider2D:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5402279313309450415}
m_Enabled: 0
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 6200000, guid: 2d231bbc8208f52c797c91aa2030f60f, type: 2}
m_IsTrigger: 0
@ -192,19 +191,3 @@ MonoBehaviour:
AlwaysReplicateAsRoot: 0
DontDestroyWithOwner: 0
AutoObjectParentSync: 1
--- !u!58 &6551590900950860653
CircleCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5402279313309450415}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 6200000, guid: 2d231bbc8208f52c797c91aa2030f60f, type: 2}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
serializedVersion: 2
m_Radius: 0.5

@ -8,8 +8,6 @@ namespace Game {
/*
* Possible optimizations:
*
* - Move to center when idle
* - Ignore impossible balls
* - Try to hit ball with edge
*/
@ -120,8 +118,9 @@ namespace Game {
var approaching = balls.Where(BallApproaches).ToList();
if (approaching.Count == 0)
return X();
return Difficulty >= Difficulty.Medium ? 0 : X();
// Nearest by Y-Distance
Ball ball = approaching.Aggregate(approaching[0], (prev, current) => YDistanceToBall(current) < YDistanceToBall(prev) ? current : prev);
Vector2 origin = ball.Rb.position;

@ -49,6 +49,9 @@ namespace Game {
}
private void Start() {
Settings.Type = Type.Hybrid;
Settings.AIDifficulty = Difficulty.Easy;
var ball = Instantiate(ballPrefab).GetComponent<Ball>();
Balls.Add(ball);
ball.Radius = 0.5f;
@ -73,7 +76,7 @@ namespace Game {
p1 = p1Obj.AddComponent<RealPlayer>();
p2 = p2Obj.AddComponent<AIPlayer>();
((RealPlayer) p1).isThisClient = true;
((AIPlayer)p2).Difficulty = Settings.AIDifficulty;
((AIPlayer) p2).Difficulty = Settings.AIDifficulty;
break;
default:
throw new ArgumentOutOfRangeException();

Loading…
Cancel
Save