From b9c07db9d0d3aa25a2ae756bf2062f6fe2ba2acf Mon Sep 17 00:00:00 2001 From: Benjamin Kraft Date: Sat, 8 Apr 2023 17:35:22 +0200 Subject: [PATCH] from medium upwards, ai goes to middle when idle --- Assets/Prefabs/Player.prefab | 21 ++------------------- Assets/Scripts/Game/AIPlayer.cs | 5 ++--- Assets/Scripts/Game/GameManager.cs | 5 ++++- 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index 9946bcd..73a2897 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -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 diff --git a/Assets/Scripts/Game/AIPlayer.cs b/Assets/Scripts/Game/AIPlayer.cs index 7d8d71c..e00cdf5 100644 --- a/Assets/Scripts/Game/AIPlayer.cs +++ b/Assets/Scripts/Game/AIPlayer.cs @@ -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; diff --git a/Assets/Scripts/Game/GameManager.cs b/Assets/Scripts/Game/GameManager.cs index b7d7e37..092047a 100644 --- a/Assets/Scripts/Game/GameManager.cs +++ b/Assets/Scripts/Game/GameManager.cs @@ -49,6 +49,9 @@ namespace Game { } private void Start() { + Settings.Type = Type.Hybrid; + Settings.AIDifficulty = Difficulty.Easy; + var ball = Instantiate(ballPrefab).GetComponent(); Balls.Add(ball); ball.Radius = 0.5f; @@ -73,7 +76,7 @@ namespace Game { p1 = p1Obj.AddComponent(); p2 = p2Obj.AddComponent(); ((RealPlayer) p1).isThisClient = true; - ((AIPlayer)p2).Difficulty = Settings.AIDifficulty; + ((AIPlayer) p2).Difficulty = Settings.AIDifficulty; break; default: throw new ArgumentOutOfRangeException();