From 7ac7e4fa890f3dfddd2cdf9af8dc35870a4b009a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Gro=C3=9F?= Date: Fri, 4 Oct 2019 21:28:32 +0200 Subject: [PATCH] Add AI Controller --- Assets/Scenes/main.unity | 896 +++++++++++++++++++++++++- Assets/Scripts/AIController.cs | 112 ++++ Assets/Scripts/AIController.cs.meta | 11 + Assets/Scripts/GameManager.cs | 4 +- Assets/Scripts/PlayerController.cs | 18 +- ProjectSettings/DynamicsManager.asset | 7 +- 6 files changed, 1029 insertions(+), 19 deletions(-) create mode 100644 Assets/Scripts/AIController.cs create mode 100644 Assets/Scripts/AIController.cs.meta diff --git a/Assets/Scenes/main.unity b/Assets/Scenes/main.unity index adcac2b..2bbbae4 100644 --- a/Assets/Scenes/main.unity +++ b/Assets/Scenes/main.unity @@ -438,6 +438,235 @@ MeshFilter: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 268360628} m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!1 &295107912 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 295107919} + - component: {fileID: 295107918} + - component: {fileID: 295107917} + - component: {fileID: 295107916} + - component: {fileID: 295107915} + - component: {fileID: 295107914} + - component: {fileID: 295107913} + m_Layer: 0 + m_Name: AI Additional + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &295107913 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 295107912} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: dbe2243f96310e94a8da761b45209311, type: 3} + m_Name: + m_EditorClassIdentifier: + ball: {fileID: 10774711} + targetGoal: {fileID: 643748445} + inputVector: {x: 0, y: 0, z: 0} + turnRadius: 6 + destinationOffset: 6.5 + distanceToTarget: 0 + angleToDestination: 0 + angleToBall: 0 + distanceToBall: 0 +--- !u!114 &295107914 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 295107912} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b77cfee0db7d5ec4a87421b180b83cd7, type: 3} + m_Name: + m_EditorClassIdentifier: + audioSource: {fileID: 295107915} + collisionSounds: + - {fileID: 8300000, guid: 81c023438803f984abf14e807b485e73, type: 3} + - {fileID: 8300000, guid: 6cef3062b893fc64cbc7e7b707b20218, type: 3} + - {fileID: 8300000, guid: 24cfc2e8f3df43642a3ecf98cd38100a, type: 3} + - {fileID: 8300000, guid: 11369db0f03d06a41b94d37f12a01a1a, type: 3} + - {fileID: 8300000, guid: 225dff5c48b88164a84497136d337530, type: 3} +--- !u!82 &295107915 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 295107912} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 0} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 0.3 + Loop: 0 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 2 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 +--- !u!65 &295107916 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 295107912} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!54 &295107917 +Rigidbody: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 295107912} + serializedVersion: 2 + m_Mass: 1 + m_Drag: 2 + m_AngularDrag: 0.05 + m_UseGravity: 1 + m_IsKinematic: 0 + m_Interpolate: 0 + m_Constraints: 84 + m_CollisionDetection: 2 +--- !u!114 &295107918 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 295107912} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d40c13a2057643a48b276db2829a33fd, type: 3} + m_Name: + m_EditorClassIdentifier: + aiControlled: 1 + playerNumber: 1 + useController: 0 + rotationSpeed: 600 + movementSpeed: 100 + rb: {fileID: 0} + forceZone: {fileID: 1657943311} + boostSpeed: 5000 + boostDuration: 0.25 + lastBoostTime: 0 + lockBoost: 0 + boostSound: {fileID: 8300000, guid: 381b83f48d13a2e4a9315848144c9b9e, type: 3} + pitchModifier: {x: 0.2, y: 0.3} +--- !u!4 &295107919 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 295107912} + m_LocalRotation: {x: 0, y: 0.7071068, z: 0, w: 0.7071068} + m_LocalPosition: {x: -31.8, y: 1, z: -5.7} + m_LocalScale: {x: 2, y: 2, z: 2} + m_Children: + - {fileID: 2145556007} + - {fileID: 1657943317} + - {fileID: 685653072} + m_Father: {fileID: 0} + m_RootOrder: 10 + m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0} --- !u!1 &304138460 GameObject: m_ObjectHideFlags: 0 @@ -482,8 +711,9 @@ GameObject: - component: {fileID: 367746329} - component: {fileID: 367746334} - component: {fileID: 367746333} + - component: {fileID: 367746335} m_Layer: 0 - m_Name: Player 2 + m_Name: Player Blue m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -530,6 +760,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d40c13a2057643a48b276db2829a33fd, type: 3} m_Name: m_EditorClassIdentifier: + aiControlled: 0 playerNumber: 2 useController: 0 rotationSpeed: 600 @@ -674,6 +905,27 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 +--- !u!114 &367746335 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 367746328} + m_Enabled: 0 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: dbe2243f96310e94a8da761b45209311, type: 3} + m_Name: + m_EditorClassIdentifier: + ball: {fileID: 10774711} + targetGoal: {fileID: 1522218632} + inputVector: {x: 0, y: 0, z: 0} + turnRadius: 6 + destinationOffset: 6.5 + distanceToTarget: 0 + angleToDestination: 0 + angleToBall: 0 + distanceToBall: 0 --- !u!1 &384291585 GameObject: m_ObjectHideFlags: 0 @@ -1050,7 +1302,7 @@ GameObject: - component: {fileID: 643748442} - component: {fileID: 643748446} m_Layer: 0 - m_Name: GoalPlayer2 + m_Name: GoalPlayerBlue m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -1221,6 +1473,106 @@ MeshFilter: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 655067603} m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!1001 &685653071 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 295107919} + m_Modifications: + - target: {fileID: -927199367670048503, guid: e20064a82392e8b419e98bf67e64f222, + type: 3} + propertyPath: m_Name + value: ship + objectReference: {fileID: 0} + - target: {fileID: -4216859302048453862, guid: e20064a82392e8b419e98bf67e64f222, + type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: -4216859302048453862, guid: e20064a82392e8b419e98bf67e64f222, + type: 3} + propertyPath: m_LocalPosition.y + value: -0 + objectReference: {fileID: 0} + - target: {fileID: -4216859302048453862, guid: e20064a82392e8b419e98bf67e64f222, + type: 3} + propertyPath: m_LocalPosition.z + value: 0.7 + objectReference: {fileID: 0} + - target: {fileID: -4216859302048453862, guid: e20064a82392e8b419e98bf67e64f222, + type: 3} + propertyPath: m_LocalRotation.x + value: 0.7071068 + objectReference: {fileID: 0} + - target: {fileID: -4216859302048453862, guid: e20064a82392e8b419e98bf67e64f222, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: -4216859302048453862, guid: e20064a82392e8b419e98bf67e64f222, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: -4216859302048453862, guid: e20064a82392e8b419e98bf67e64f222, + type: 3} + propertyPath: m_LocalRotation.w + value: 0.7071068 + objectReference: {fileID: 0} + - target: {fileID: -4216859302048453862, guid: e20064a82392e8b419e98bf67e64f222, + type: 3} + propertyPath: m_RootOrder + value: 2 + objectReference: {fileID: 0} + - target: {fileID: -4216859302048453862, guid: e20064a82392e8b419e98bf67e64f222, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 90 + objectReference: {fileID: 0} + - target: {fileID: -4216859302048453862, guid: e20064a82392e8b419e98bf67e64f222, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: -4216859302048453862, guid: e20064a82392e8b419e98bf67e64f222, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: -1504981713932161579, guid: e20064a82392e8b419e98bf67e64f222, + type: 3} + propertyPath: m_Materials.Array.data[0] + value: + objectReference: {fileID: 2100000, guid: c3862b83618c1d5458bea8944cabf466, type: 2} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: e20064a82392e8b419e98bf67e64f222, type: 3} +--- !u!4 &685653072 stripped +Transform: + m_CorrespondingSourceObject: {fileID: -4216859302048453862, guid: e20064a82392e8b419e98bf67e64f222, + type: 3} + m_PrefabInstance: {fileID: 685653071} + m_PrefabAsset: {fileID: 0} +--- !u!1 &685653073 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: -927199367670048503, guid: e20064a82392e8b419e98bf67e64f222, + type: 3} + m_PrefabInstance: {fileID: 685653071} + m_PrefabAsset: {fileID: 0} +--- !u!64 &685653074 +MeshCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 685653073} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 3 + m_Convex: 1 + m_CookingOptions: 14 + m_Mesh: {fileID: -5495902117074765545, guid: e20064a82392e8b419e98bf67e64f222, type: 3} --- !u!1 &697913064 GameObject: m_ObjectHideFlags: 0 @@ -1405,8 +1757,9 @@ GameObject: - component: {fileID: 708460345} - component: {fileID: 708460349} - component: {fileID: 708460348} + - component: {fileID: 708460350} m_Layer: 0 - m_Name: Player 3 + m_Name: Player Red m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -1470,8 +1823,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d40c13a2057643a48b276db2829a33fd, type: 3} m_Name: m_EditorClassIdentifier: - playerNumber: 3 - useController: 1 + aiControlled: 1 + playerNumber: 1 + useController: 0 rotationSpeed: 600 movementSpeed: 100 rb: {fileID: 0} @@ -1597,6 +1951,27 @@ AudioSource: m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 +--- !u!114 &708460350 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 708460343} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: dbe2243f96310e94a8da761b45209311, type: 3} + m_Name: + m_EditorClassIdentifier: + ball: {fileID: 10774711} + targetGoal: {fileID: 643748445} + inputVector: {x: 0, y: 0, z: 0} + turnRadius: 6 + destinationOffset: 6.5 + distanceToTarget: 0 + angleToDestination: 0 + angleToBall: 0 + distanceToBall: 0 --- !u!1 &929235626 GameObject: m_ObjectHideFlags: 0 @@ -1609,13 +1984,15 @@ GameObject: - component: {fileID: 929235629} - component: {fileID: 929235628} - component: {fileID: 929235627} + - component: {fileID: 929235631} + - component: {fileID: 929235632} m_Layer: 0 - m_Name: Player 1 + m_Name: Player Additional m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!65 &929235627 BoxCollider: m_ObjectHideFlags: 0 @@ -1657,8 +2034,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d40c13a2057643a48b276db2829a33fd, type: 3} m_Name: m_EditorClassIdentifier: - playerNumber: 1 - useController: 0 + aiControlled: 0 + playerNumber: 3 + useController: 1 rotationSpeed: 600 movementSpeed: 100 rb: {fileID: 0} @@ -1667,8 +2045,8 @@ MonoBehaviour: boostDuration: 0.25 lastBoostTime: 0 lockBoost: 0 - boostSound: {fileID: 0} - pitchModifier: {x: 0, y: 0} + boostSound: {fileID: 8300000, guid: 381b83f48d13a2e4a9315848144c9b9e, type: 3} + pitchModifier: {x: 0.2, y: 0.3} --- !u!4 &929235630 Transform: m_ObjectHideFlags: 0 @@ -1677,7 +2055,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 929235626} m_LocalRotation: {x: 0, y: -0.7071068, z: 0, w: 0.7071068} - m_LocalPosition: {x: -0.3, y: 1, z: 13.3} + m_LocalPosition: {x: 31, y: 1, z: 8.9} m_LocalScale: {x: 2, y: 2, z: 2} m_Children: - {fileID: 966074800} @@ -1686,6 +2064,121 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 9 m_LocalEulerAnglesHint: {x: 0, y: -90, z: 0} +--- !u!82 &929235631 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 929235626} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 0} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 0 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 +--- !u!114 &929235632 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 929235626} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b77cfee0db7d5ec4a87421b180b83cd7, type: 3} + m_Name: + m_EditorClassIdentifier: + audioSource: {fileID: 929235631} + collisionSounds: + - {fileID: 8300000, guid: 81c023438803f984abf14e807b485e73, type: 3} + - {fileID: 8300000, guid: 6cef3062b893fc64cbc7e7b707b20218, type: 3} + - {fileID: 8300000, guid: 24cfc2e8f3df43642a3ecf98cd38100a, type: 3} + - {fileID: 8300000, guid: 11369db0f03d06a41b94d37f12a01a1a, type: 3} + - {fileID: 8300000, guid: 225dff5c48b88164a84497136d337530, type: 3} --- !u!1 &963194225 GameObject: m_ObjectHideFlags: 0 @@ -2208,6 +2701,7 @@ GameObject: - component: {fileID: 1248323376} - component: {fileID: 1248323375} - component: {fileID: 1248323374} + - component: {fileID: 1248323379} m_Layer: 0 m_Name: ForceZone m_TagString: Untagged @@ -2302,6 +2796,102 @@ Transform: m_Father: {fileID: 929235630} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!82 &1248323379 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1248323373} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 0} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 0 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 --- !u!1 &1463368301 GameObject: m_ObjectHideFlags: 0 @@ -2751,6 +3341,210 @@ MonoBehaviour: m_EditorClassIdentifier: gm: {fileID: 0} playerNumber: 1 +--- !u!1 &1657943311 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1657943317} + - component: {fileID: 1657943316} + - component: {fileID: 1657943315} + - component: {fileID: 1657943314} + - component: {fileID: 1657943313} + - component: {fileID: 1657943312} + m_Layer: 0 + m_Name: ForceZone + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!82 &1657943312 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1657943311} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 0} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 0 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 +--- !u!114 &1657943313 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1657943311} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5ee5ed52ae75cde4cadf0d7de9efa9f0, type: 3} + m_Name: + m_EditorClassIdentifier: + force: 2200 + player: {fileID: 2145556004} +--- !u!65 &1657943314 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1657943311} + m_Material: {fileID: 0} + m_IsTrigger: 1 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &1657943315 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1657943311} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: f3060dffc19587941ab40540b4aa9398, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!33 &1657943316 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1657943311} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &1657943317 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1657943311} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0.39, z: -2.8} + m_LocalScale: {x: 1.8, y: 1, z: 4} + m_Children: [] + m_Father: {fileID: 295107919} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1831066455 GameObject: m_ObjectHideFlags: 0 @@ -3401,3 +4195,81 @@ PrefabInstance: objectReference: {fileID: 2100000, guid: c3862b83618c1d5458bea8944cabf466, type: 2} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: e20064a82392e8b419e98bf67e64f222, type: 3} +--- !u!1 &2145556004 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2145556007} + - component: {fileID: 2145556006} + - component: {fileID: 2145556005} + m_Layer: 0 + m_Name: Player3 + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!23 &2145556005 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2145556004} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 +--- !u!33 &2145556006 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2145556004} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &2145556007 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2145556004} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: -0.3} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 295107919} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Scripts/AIController.cs b/Assets/Scripts/AIController.cs new file mode 100644 index 0000000..474824e --- /dev/null +++ b/Assets/Scripts/AIController.cs @@ -0,0 +1,112 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class AIController : MonoBehaviour +{ + public GameObject ball; + public Transform targetGoal; + public Vector3 inputVector; + public float turnRadius = 1; + public float destinationOffset; + + public float distanceToTarget; + public float angleToDestination; + public float angleToBall; + public float distanceToBall; + + private Vector3 destination; + private Vector3 directionVector; + // Start is called before the first frame update + void Start() + { + + } + + // Update is called once per frame + void Update() + { + Vector3 ballPosition = this.ball.transform.position; + Vector3 goalDirection = ballPosition - this.targetGoal.position; + this.destination = ballPosition + goalDirection.normalized * this.destinationOffset; + this.directionVector = this.destination - this.transform.position; + + //Use "right" to offset the angle by 90 deg. This gives us a positive/negative value + // depending on the direction we have to rotate + this.angleToDestination = Vector3.Dot(this.transform.right, this.directionVector.normalized); + + this.angleToBall = Mathf.Acos(Vector3.Dot((ballPosition - this.transform.position).normalized, this.transform.forward)) * Mathf.Rad2Deg; + this.angleToBall = this.Angle360(transform.position, ballPosition, Vector3.right); + this.distanceToTarget = Vector3.Distance(this.transform.position, this.destination); + this.distanceToBall = Vector3.Distance(this.transform.position, ballPosition); + + } + + float Angle360(Vector3 from, Vector3 to, Vector3 right) + { + float angle = Vector3.Angle(from, to); + return (Vector3.Angle(right, to) > 90f) ? 360f - angle : angle; + } + + private void OnDrawGizmos() + { + Debug.DrawLine(this.transform.position, this.destination, Color.yellow, 0f, false); + Debug.DrawLine(this.targetGoal.position, this.destination, Color.yellow, 0f, false); + Gizmos.DrawSphere(this.destination, 1); + Debug.DrawRay(transform.position, this.transform.forward * 10, Color.green); + Debug.DrawRay(transform.position, this.directionVector.normalized * 10, Color.red); + + } + + + public float[] GetInputs() + { + float[] inputs = new float[3]; + + inputs[AiInputs.VERTICAL] = 0; + inputs[AiInputs.BOOST] = 0; + + if (this.distanceToTarget > 4) + { + inputs[AiInputs.VERTICAL] = 1; + } + + + inputs[AiInputs.HORIZONTAL] = Mathf.Floor(this.angleToDestination * 10) / 10; + if (this.distanceToTarget < this.turnRadius) + { + inputs[AiInputs.HORIZONTAL] = Mathf.Floor(-this.angleToBall * 10) / 10; + Debug.DrawRay(transform.position, transform.TransformDirection(-Vector3.forward) * 10, Color.magenta, 0,false); + if (Physics.Raycast(transform.position, transform.TransformDirection(-Vector3.forward), 10)) + { + inputs[AiInputs.BOOST] = 1; + } + + + } + + if (this.distanceToBall < this.turnRadius) + { + RaycastHit hit; + inputs[AiInputs.HORIZONTAL] = Mathf.Floor(-this.angleToBall * 10) / 10; + if (Physics.Raycast(transform.position, this.directionVector, out hit, 5)) + { + if(hit.transform.tag == "Ball") + { + inputs[AiInputs.BOOST] = 1; + } + } + } + + this.inputVector = new Vector3(inputs[AiInputs.HORIZONTAL], inputs[AiInputs.VERTICAL], inputs[AiInputs.BOOST]); + //Left/Right, Fwd/Bkwd, Boost + return inputs; + } +} + +public static class AiInputs +{ + public const int HORIZONTAL = 0; + public const int VERTICAL = 1; + public const int BOOST = 2; +} \ No newline at end of file diff --git a/Assets/Scripts/AIController.cs.meta b/Assets/Scripts/AIController.cs.meta new file mode 100644 index 0000000..ebf5e91 --- /dev/null +++ b/Assets/Scripts/AIController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dbe2243f96310e94a8da761b45209311 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index add3bb9..1738b57 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -45,8 +45,8 @@ public class GameManager : MonoBehaviour // Update is called once per frame void Update() { - Debug.Log("Calculating matrix: Vector(" + Time.deltaTime * Random.Range(12, 123) + ")"); - Debug.Log("Hacking pentagon: in pr0gress..."); + //Debug.Log("Calculating matrix: Vector(" + Time.deltaTime * Random.Range(12, 123) + ")"); + //Debug.Log("Hacking pentagon: in pr0gress..."); this.scoreLabel.text = "Score: " + this.scorePlayer1 + " : " + this.scorePlayer2; if (this.scorePlayer1 >= maxGoals) diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 9f2466f..c15ef0d 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -4,6 +4,7 @@ using UnityEngine; public class PlayerController : MonoBehaviour { + public bool aiControlled = false; public string playerNumber; public bool useController = false; public float rotationSpeed = 100; @@ -18,12 +19,16 @@ public class PlayerController : MonoBehaviour public Vector2 pitchModifier; private AudioSource audioSource; - + private AIController aiController; // Start is called before the first frame update void Start() { this.audioSource = this.forceZone.transform.GetComponent(); this.rb = GetComponent(); + if (this.aiControlled) + { + this.aiController = GetComponent(); + } } // Update is called once per frame @@ -31,6 +36,15 @@ public class PlayerController : MonoBehaviour { float rotationDirection = Input.GetAxis("Horizontal" + this.playerNumber); float movementDirection = Input.GetAxis("Vertical" + this.playerNumber); + float[] aiInput = new float[3]; + + //Override any inputs if this instance is to be controlled by AI + if (this.aiControlled) + { + aiInput = this.aiController.GetInputs(); + rotationDirection = aiInput[AiInputs.HORIZONTAL]; + movementDirection = aiInput[AiInputs.VERTICAL]; + } if (this.useController) { //Debug.Log(Input.GetAxis("VerticalBack" + this.playerNumber)); @@ -62,7 +76,7 @@ public class PlayerController : MonoBehaviour } //Boost - if (Input.GetButtonDown("Boost" + this.playerNumber) && !this.lockBoost) + if (Input.GetButtonDown("Boost" + this.playerNumber) || aiInput[AiInputs.BOOST] > 0 && !this.lockBoost) { this.audioSource.clip = this.boostSound; this.audioSource.pitch = Random.Range(this.pitchModifier.x, this.pitchModifier.y); diff --git a/ProjectSettings/DynamicsManager.asset b/ProjectSettings/DynamicsManager.asset index cdc1f3e..09c144e 100644 --- a/ProjectSettings/DynamicsManager.asset +++ b/ProjectSettings/DynamicsManager.asset @@ -3,13 +3,13 @@ --- !u!55 &1 PhysicsManager: m_ObjectHideFlags: 0 - serializedVersion: 11 + serializedVersion: 13 m_Gravity: {x: 0, y: -9.81, z: 0} m_DefaultMaterial: {fileID: 0} m_BounceThreshold: 2 m_SleepThreshold: 0.005 m_DefaultContactOffset: 0.01 - m_DefaultSolverIterations: 6 + m_DefaultSolverIterations: 12 m_DefaultSolverVelocityIterations: 1 m_QueriesHitBackfaces: 0 m_QueriesHitTriggers: 1 @@ -22,6 +22,7 @@ PhysicsManager: m_AutoSyncTransforms: 0 m_ReuseCollisionCallbacks: 1 m_ClothInterCollisionSettingsToggle: 0 + m_ClothGravity: {x: 0, y: -9.81, z: 0} m_ContactPairsMode: 0 m_BroadphaseType: 0 m_WorldBounds: @@ -31,4 +32,4 @@ PhysicsManager: m_FrictionType: 0 m_EnableEnhancedDeterminism: 0 m_EnableUnifiedHeightmaps: 1 - m_DefaultMaxAngluarSpeed: 7 + m_DefaultMaxAngularSpeed: 7