From 67c86ed960cc5feaedd06569ad62a340cc0d013f Mon Sep 17 00:00:00 2001 From: Carson Katri Date: Sat, 12 Jun 2021 18:06:04 -0400 Subject: Functional AI that can dribble, steal, and shoot --- Assets/Prefabs/Enemy.prefab | 68 +++++--- Assets/Prefabs/Player.prefab | 176 ++++++++++++++------- Assets/Scenes/Main.unity | 7 +- Assets/Scripts/Controllers/AIController.cs | 11 +- Assets/Scripts/Controllers/Ball.cs | 10 +- Assets/Scripts/Controllers/CameraController.cs | 3 +- Assets/Scripts/Controllers/GameController.cs | 6 +- .../Scripts/Controllers/Player/PlayerController.cs | 5 + Assets/Scripts/Controllers/Player/PlayerSegment.cs | 2 + 9 files changed, 202 insertions(+), 86 deletions(-) diff --git a/Assets/Prefabs/Enemy.prefab b/Assets/Prefabs/Enemy.prefab index 14429da..3a96a43 100644 --- a/Assets/Prefabs/Enemy.prefab +++ b/Assets/Prefabs/Enemy.prefab @@ -1,5 +1,41 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!1 &2146946035065629339 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6222230847746125055} + m_Layer: 8 + m_Name: Sprites + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6222230847746125055 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2146946035065629339} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 7079067999656997561} + - {fileID: 7079068000117515304} + - {fileID: 7079067998874270570} + - {fileID: 7079067999404952341} + - {fileID: 7079067998994176362} + - {fileID: 7079067998564477638} + m_Father: {fileID: 7079067999241254396} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &7079067998564477639 GameObject: m_ObjectHideFlags: 0 @@ -25,11 +61,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7079067998564477639} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.079999976, y: 0.9599999, z: 0} + m_LocalPosition: {x: -0.07999992, y: 0.9599999, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: - {fileID: 7079068000273710487} - m_Father: {fileID: 7079067999241254396} + m_Father: {fileID: 6222230847746125055} m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &7079067998564477637 @@ -108,10 +144,10 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7079067998874270571} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0.24000001, y: 1.7199999, z: 0} + m_LocalPosition: {x: 0.24000001, y: 1.72, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 7079067999241254396} + m_Father: {fileID: 6222230847746125055} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &7079067998874270569 @@ -272,11 +308,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7079067998994176363} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0.12000002, y: 0.9599999, z: 0} + m_LocalPosition: {x: 0.120000005, y: 0.9599999, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: - {fileID: 7079067998927418495} - m_Father: {fileID: 7079067999241254396} + m_Father: {fileID: 6222230847746125055} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &7079067998994176361 @@ -360,12 +396,7 @@ Transform: m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - - {fileID: 7079067999656997561} - - {fileID: 7079068000117515304} - - {fileID: 7079067998874270570} - - {fileID: 7079067999404952341} - - {fileID: 7079067998994176362} - - {fileID: 7079067998564477638} + - {fileID: 6222230847746125055} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -382,6 +413,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: speed: 2 + flipper: {fileID: 6222230847746125055} leftLeg: top: {fileID: 7079067998994176363} bottom: {fileID: 7079067998927418464} @@ -464,10 +496,10 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7079067999404952342} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.07999998, y: 1.7199999, z: 0} + m_LocalPosition: {x: -0.08000004, y: 1.72, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 7079067999241254396} + m_Father: {fileID: 6222230847746125055} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &7079067999404952340 @@ -546,10 +578,10 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7079067999656997562} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0.000000007450581, y: 1.8399999, z: 0} + m_LocalPosition: {x: 0, y: 1.8399999, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 7079067999241254396} + m_Father: {fileID: 6222230847746125055} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &7079067999656997560 @@ -628,10 +660,10 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7079068000117515305} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0.08, y: 1.4, z: 0} + m_LocalPosition: {x: 0.08000004, y: 1.4, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 7079067999241254396} + m_Father: {fileID: 6222230847746125055} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &7079068000117515303 diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index a7aaff7..331a664 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -25,11 +25,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 61032117990659215} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.16, y: 0.22000027, z: 0} + m_LocalPosition: {x: -0.15999997, y: 0.22000027, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 6095859833589646295} - m_RootOrder: 6 + m_Father: {fileID: 4056543971366857326} + m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &5936857703093018383 SpriteRenderer: @@ -107,11 +107,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 168482877463247243} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.23999996, y: -0.1400001, z: 0} + m_LocalPosition: {x: -0.23999989, y: -0.1400001, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 6095859833589646295} - m_RootOrder: 2 + m_Father: {fileID: 4056543971366857326} + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &3459380805264537065 SpriteRenderer: @@ -189,11 +189,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 414971659141114100} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.000000007450581, y: -0.36000013, z: 0} + m_LocalPosition: {x: 0, y: -0.36000013, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 6095859832867562448} - m_RootOrder: 3 + m_Father: {fileID: 5232080199619218326} + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &7378570828369499491 SpriteRenderer: @@ -353,11 +353,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1155082106432933183} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.23999998, y: -0.32000017, z: 0} + m_LocalPosition: {x: -0.23999989, y: -0.32000017, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 6095859832867562448} - m_RootOrder: 2 + m_Father: {fileID: 5232080199619218326} + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &9223032480722665561 SpriteRenderer: @@ -410,6 +410,43 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 +--- !u!1 &1299133037034953548 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 5232080199619218326} + m_Layer: 6 + m_Name: Sprites + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &5232080199619218326 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1299133037034953548} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 3736503195004337046} + - {fileID: 1950673337898001336} + - {fileID: 4617615456759737811} + - {fileID: 5036223590975315366} + - {fileID: 4926619347039342894} + - {fileID: 6584415796429336198} + - {fileID: 5563519660449435181} + m_Father: {fileID: 6095859832867562448} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1726427273403640951 GameObject: m_ObjectHideFlags: 0 @@ -435,11 +472,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1726427273403640951} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.04, y: 0.17999992, z: 0} + m_LocalPosition: {x: -0.03999996, y: 0.17999995, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 6095859833589646295} - m_RootOrder: 7 + m_Father: {fileID: 4056543971366857326} + m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &1253643785299289774 SpriteRenderer: @@ -517,11 +554,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2835159121523199489} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0.08, y: -0.18000007, z: 0} + m_LocalPosition: {x: 0.08000004, y: -0.18000007, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 6095859833589646295} - m_RootOrder: 3 + m_Father: {fileID: 4056543971366857326} + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &3309077257564135105 SpriteRenderer: @@ -599,11 +636,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3531439111263992317} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.039999984, y: -0.18000007, z: 0} + m_LocalPosition: {x: -0.03999996, y: -0.18000007, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 6095859833589646295} - m_RootOrder: 4 + m_Father: {fileID: 4056543971366857326} + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &2252780374825515412 SpriteRenderer: @@ -845,11 +882,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5566193515297851100} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.039999984, y: 0.26000023, z: 0} + m_LocalPosition: {x: -0.03999996, y: 0.26000023, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 6095859833589646295} - m_RootOrder: 1 + m_Father: {fileID: 4056543971366857326} + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &6152898792764514060 SpriteRenderer: @@ -927,11 +964,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5783560377927676884} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.04, y: -0.30000043, z: 0} + m_LocalPosition: {x: -0.03999996, y: -0.30000043, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 6095859832867562448} - m_RootOrder: 7 + m_Father: {fileID: 5232080199619218326} + m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &5753362173665439702 SpriteRenderer: @@ -1009,11 +1046,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 5886521033835613979} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.12, y: -0.36000013, z: 0} + m_LocalPosition: {x: -0.120000005, y: -0.36000013, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 6095859832867562448} - m_RootOrder: 4 + m_Father: {fileID: 5232080199619218326} + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &2059075423582568814 SpriteRenderer: @@ -1098,13 +1135,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 4383152884674024269} - - {fileID: 3736503195004337046} - - {fileID: 1950673337898001336} - - {fileID: 4617615456759737811} - - {fileID: 5036223590975315366} - - {fileID: 4926619347039342894} - - {fileID: 6584415796429336198} - - {fileID: 5563519660449435181} + - {fileID: 5232080199619218326} m_Father: {fileID: 6095859834264611321} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -1134,6 +1165,7 @@ MonoBehaviour: height: 0 isRoot: 0 isTop: 1 + flipper: {fileID: 5232080199619218326} --- !u!50 &6095859832867562452 Rigidbody2D: serializedVersion: 4 @@ -1392,13 +1424,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 6008469425673925979} - - {fileID: 4089110449282737221} - - {fileID: 262767061358356167} - - {fileID: 125789255435185866} - - {fileID: 58003308918906493} - - {fileID: 2429958341132927238} - - {fileID: 5588061831825342868} - - {fileID: 4021439886403308905} + - {fileID: 4056543971366857326} m_Father: {fileID: 6095859834264611321} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -1428,6 +1454,7 @@ MonoBehaviour: height: 0 isRoot: 1 isTop: 0 + flipper: {fileID: 4056543971366857326} --- !u!50 &6095859833589646292 Rigidbody2D: serializedVersion: 4 @@ -1557,11 +1584,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6791963013674012835} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0.08, y: 0.22000027, z: 0} + m_LocalPosition: {x: 0.08000004, y: 0.22000027, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 6095859833589646295} - m_RootOrder: 5 + m_Father: {fileID: 4056543971366857326} + m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &5735974347887600543 SpriteRenderer: @@ -1785,11 +1812,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8138150617172078869} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.04, y: 0.07999992, z: 0} + m_LocalPosition: {x: -0.03999996, y: 0.07999992, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 6095859832867562448} - m_RootOrder: 1 + m_Father: {fileID: 5232080199619218326} + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &2052168321038957812 SpriteRenderer: @@ -1867,11 +1894,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8549221634172624537} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0.08, y: 0.03999996, z: 0} + m_LocalPosition: {x: 0.08000004, y: 0.03999996, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 6095859832867562448} - m_RootOrder: 5 + m_Father: {fileID: 5232080199619218326} + m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &5355852279616931264 SpriteRenderer: @@ -1924,6 +1951,43 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 +--- !u!1 &8620585703101697276 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 4056543971366857326} + m_Layer: 6 + m_Name: Sprites + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4056543971366857326 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8620585703101697276} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 4089110449282737221} + - {fileID: 262767061358356167} + - {fileID: 125789255435185866} + - {fileID: 58003308918906493} + - {fileID: 2429958341132927238} + - {fileID: 5588061831825342868} + - {fileID: 4021439886403308905} + m_Father: {fileID: 6095859833589646295} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &8845918641001187994 GameObject: m_ObjectHideFlags: 0 @@ -1949,11 +2013,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8845918641001187994} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.16, y: 0.03999996, z: 0} + m_LocalPosition: {x: -0.15999997, y: 0.03999996, z: 0} m_LocalScale: {x: 4, y: 4, z: 1} m_Children: [] - m_Father: {fileID: 6095859832867562448} - m_RootOrder: 6 + m_Father: {fileID: 5232080199619218326} + m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &1559589370631777136 SpriteRenderer: diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 769348d..3a19e19 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -237,6 +237,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: target: {fileID: 288486053} + speed: 5 --- !u!20 &519420031 Camera: m_ObjectHideFlags: 0 @@ -399,7 +400,7 @@ PrefabInstance: objectReference: {fileID: 984947993} - target: {fileID: 670472073231852718, guid: d9b5414ac39834728992e2585c5ad778, type: 3} propertyPath: legSpeed - value: 5 + value: 30 objectReference: {fileID: 0} - target: {fileID: 7079067999241254396, guid: d9b5414ac39834728992e2585c5ad778, type: 3} propertyPath: m_RootOrder @@ -473,11 +474,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 6095859834264611321, guid: c64ad9b908cb44602b3d13a74aef751f, type: 3} propertyPath: m_LocalPosition.x - value: -0.10864201 + value: -1.9086419 objectReference: {fileID: 0} - target: {fileID: 6095859834264611321, guid: c64ad9b908cb44602b3d13a74aef751f, type: 3} propertyPath: m_LocalPosition.y - value: -0.11388469 + value: -2.1138847 objectReference: {fileID: 0} - target: {fileID: 6095859834264611321, guid: c64ad9b908cb44602b3d13a74aef751f, type: 3} propertyPath: m_LocalPosition.z diff --git a/Assets/Scripts/Controllers/AIController.cs b/Assets/Scripts/Controllers/AIController.cs index 0edffb7..f897f42 100644 --- a/Assets/Scripts/Controllers/AIController.cs +++ b/Assets/Scripts/Controllers/AIController.cs @@ -10,6 +10,8 @@ namespace Controllers public class AIController : MonoBehaviour { [SerializeField] private float speed; + + [SerializeField] private Transform flipper; [Header("Legs")] [SerializeField] private Leg leftLeg; @@ -59,11 +61,18 @@ namespace Controllers else { // transform.position += new Vector3(game.ball.transform.position.x - transform.position.x, 0f, 0f).normalized * (Time.deltaTime * speed); - transform.position = new Vector2(Vector2.MoveTowards(transform.position, game.ball.transform.position, speed * Time.deltaTime).x, transform.position.y); + var direction = Vector2.MoveTowards(transform.position, game.ball.transform.position, speed * Time.deltaTime); + transform.position = new Vector2(direction.x, transform.position.y); + flipper.localScale = new Vector3((Vector2.Distance(transform.position, direction) > 0 ? -1f : 1f), 1, 1); } } else // Otherwise, move toward the basket, and then once we get within range, take the shot. { + transform.position = new Vector2(Vector2.MoveTowards(transform.position, game.EnemyHoop.transform.position, speed * Time.deltaTime).x, transform.position.y); + if (Mathf.Abs(transform.position.x - game.EnemyHoop.transform.position.x) < 5f) // Take the shot. + { + game.enemy.Shoot(transform); + } } movement -= transform.position; diff --git a/Assets/Scripts/Controllers/Ball.cs b/Assets/Scripts/Controllers/Ball.cs index fa9c251..45e607b 100644 --- a/Assets/Scripts/Controllers/Ball.cs +++ b/Assets/Scripts/Controllers/Ball.cs @@ -17,12 +17,12 @@ namespace Controllers controller.BallDropped(); } - public void Shoot(Transform playerTransform) + public void Shoot(Vector3 target) { - transform.right = (controller.PlayerHoop.transform.position - transform.position); - var rigidbody = GetComponent(); - rigidbody.velocity = Vector2.zero; - rigidbody.AddForce(transform.right * shotForce); + transform.right = (target - transform.position); + var rb = GetComponent(); + rb.velocity = Vector2.zero; + rb.AddForce((transform.right + (transform.up * 0.5f)) * shotForce); } } } diff --git a/Assets/Scripts/Controllers/CameraController.cs b/Assets/Scripts/Controllers/CameraController.cs index a72b2f4..faffbe5 100644 --- a/Assets/Scripts/Controllers/CameraController.cs +++ b/Assets/Scripts/Controllers/CameraController.cs @@ -5,10 +5,11 @@ namespace Controllers public class CameraController : MonoBehaviour { [SerializeField] private Transform target; + [SerializeField] private float speed; private void Update() { - transform.position = new Vector3(target.transform.position.x, target.transform.position.y, -10f); + transform.position = Vector3.MoveTowards(transform.position, new Vector3(target.transform.position.x, target.transform.position.y, -10f), Time.deltaTime * speed); } } } diff --git a/Assets/Scripts/Controllers/GameController.cs b/Assets/Scripts/Controllers/GameController.cs index 646b750..1573405 100644 --- a/Assets/Scripts/Controllers/GameController.cs +++ b/Assets/Scripts/Controllers/GameController.cs @@ -60,6 +60,8 @@ namespace Controllers private State dribble => isEnemy ? State.EnemyDribble : State.PlayerDribble; private State shoot => isEnemy ? State.EnemyShoot : State.PlayerShoot; + private Hoop hoop => isEnemy ? controller.EnemyHoop : controller.PlayerHoop; + public bool HasBall => controller.state == dribble; /// @@ -80,7 +82,7 @@ namespace Controllers public bool GrabBall(Vector2 handPosition) { // Don't allow the ball to be picked up if someone shot it. Also don't try picking it up if we're already holding it. - //if (controller.state.IsShot() || controller.state == dribble) return false; + if (controller.state == shoot || controller.state == dribble) return false; // Make sure its within their grab area. if (Vector2.Distance(controller.ball.transform.position, handPosition) > 0.75f) return false; @@ -99,7 +101,7 @@ namespace Controllers { if (controller.state != dribble) return false; // We must be dribbling the ball to shoot it. controller.state = shoot; - controller.ball.Shoot(playerTransform); + controller.ball.Shoot(hoop.transform.position); lastShotPosition = playerTransform.position; return true; } diff --git a/Assets/Scripts/Controllers/Player/PlayerController.cs b/Assets/Scripts/Controllers/Player/PlayerController.cs index 6436235..c789ccb 100644 --- a/Assets/Scripts/Controllers/Player/PlayerController.cs +++ b/Assets/Scripts/Controllers/Player/PlayerController.cs @@ -2,6 +2,7 @@ using System; using System.Linq; using Controllers.Player; using UnityEngine; +using Random = UnityEngine.Random; namespace Controllers.Player { @@ -35,6 +36,9 @@ namespace Controllers.Player { var segment = segments[i]; + // Flip the player to face the right direction. + segment.transform.localScale = root.Rigidbody.velocity.x > 0.01f ? new Vector3(1f, 1f, 1f) : new Vector3(-1f, 1f, 1f); + // Update icons foreach (var control in new[] {segment.left, segment.right}) { @@ -85,6 +89,7 @@ namespace Controllers.Player if (Input.GetKeyDown(controls.grab)) { // Try grabbing at each segment, and then the segment can pass it up to the top guy. + if (game.enemy.HasBall && Random.Range(0, 100) < 50) return; // 50% chance of stealing. foreach (var segment in segments) { if (game.player.GrabBall(segment.transform.position)) break; // Stop after we successfully grab. diff --git a/Assets/Scripts/Controllers/Player/PlayerSegment.cs b/Assets/Scripts/Controllers/Player/PlayerSegment.cs index 4d0fb4f..0e8a969 100644 --- a/Assets/Scripts/Controllers/Player/PlayerSegment.cs +++ b/Assets/Scripts/Controllers/Player/PlayerSegment.cs @@ -21,6 +21,8 @@ namespace Controllers.Player [SerializeField] public bool isRoot; [SerializeField] public bool isTop; + [SerializeField] public Transform flipper; + public Rigidbody2D Rigidbody => _rigidbody != null ? _rigidbody : _rigidbody = GetComponent(); private Rigidbody2D _rigidbody; -- cgit v1.2.3-56-ge451