From a2eff8100971c3683a19c37e66063d7c16fc669d Mon Sep 17 00:00:00 2001 From: Amaan Shawkath Date: Sun, 13 Jun 2021 00:58:25 +0100 Subject: [PATCH] made wheel rotates and fixed collision - walls need box colliders adding --- Assets/Models/Amain.unity | 204 +++++++++++++++++++++++++++++-- Assets/Prefabs/Spot.prefab | 59 ++++++++- Assets/SpotController.cs | 34 +++++- ProjectSettings/TagManager.asset | 4 +- 4 files changed, 286 insertions(+), 15 deletions(-) diff --git a/Assets/Models/Amain.unity b/Assets/Models/Amain.unity index 064389c..4dcd6e2 100644 --- a/Assets/Models/Amain.unity +++ b/Assets/Models/Amain.unity @@ -360,6 +360,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5e454d0c686916f45856da8b9d021191, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!1 &399020193 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 5764007707003976729, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + m_PrefabInstance: {fileID: 3129800594024812082} + m_PrefabAsset: {fileID: 0} --- !u!1 &506618578 GameObject: m_ObjectHideFlags: 0 @@ -584,13 +589,71 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 10 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &552528065 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 431178397659895055, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + m_PrefabInstance: {fileID: 3129800594024812082} + m_PrefabAsset: {fileID: 0} +--- !u!1 &593387668 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 593387671} + - component: {fileID: 593387670} + - component: {fileID: 593387669} + m_Layer: 0 + m_Name: Cube (2) + m_TagString: Wall + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!65 &593387669 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 593387668} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1, z: 0.5209484} + m_Center: {x: 0, y: 0, z: -0.037077904} +--- !u!33 &593387670 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 593387668} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &593387671 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 593387668} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -1.5124, y: 4.4869, z: 26.47} + m_LocalScale: {x: 21.70243, y: 5.369851, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 22 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!43 &732167896 Mesh: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: pb_Mesh25928 + m_Name: pb_Mesh25902 serializedVersion: 10 m_SubMeshes: - serializedVersion: 2 @@ -1019,6 +1082,11 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 7 m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0} +--- !u!1 &1091839670 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 4391365009072602997, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + m_PrefabInstance: {fileID: 3129800594024812082} + m_PrefabAsset: {fileID: 0} --- !u!1 &1111540375 GameObject: m_ObjectHideFlags: 0 @@ -1211,6 +1279,11 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 11 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1306672502 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 4712379551056951868, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + m_PrefabInstance: {fileID: 3129800594024812082} + m_PrefabAsset: {fileID: 0} --- !u!20 &1332572027 stripped Camera: m_CorrespondingSourceObject: {fileID: 9005220659476430821, guid: 2d3a85ecde41a8246a79669975912b74, type: 3} @@ -1221,6 +1294,27 @@ GameObject: m_CorrespondingSourceObject: {fileID: 5734351610328079135, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} m_PrefabInstance: {fileID: 3129800594024812082} m_PrefabAsset: {fileID: 0} +--- !u!1 &1482868362 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 3129800593820501904, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + m_PrefabInstance: {fileID: 3129800594024812082} + m_PrefabAsset: {fileID: 0} +--- !u!54 &1482868366 +Rigidbody: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1482868362} + serializedVersion: 2 + m_Mass: 1 + m_Drag: 0 + m_AngularDrag: 0.05 + m_UseGravity: 1 + m_IsKinematic: 0 + m_Interpolate: 0 + m_Constraints: 0 + m_CollisionDetection: 0 --- !u!1 &1506324192 GameObject: m_ObjectHideFlags: 0 @@ -1925,6 +2019,11 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1937114486 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 1269607093256655120, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + m_PrefabInstance: {fileID: 3129800594024812082} + m_PrefabAsset: {fileID: 0} --- !u!1 &2033690144 GameObject: m_ObjectHideFlags: 0 @@ -2021,6 +2120,11 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 12 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &2035943281 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 1570633890004696089, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + m_PrefabInstance: {fileID: 3129800594024812082} + m_PrefabAsset: {fileID: 0} --- !u!1 &2057178508 GameObject: m_ObjectHideFlags: 0 @@ -2282,7 +2386,7 @@ MeshCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 4 - m_Convex: 0 + m_Convex: 1 m_CookingOptions: 30 m_Mesh: {fileID: 732167896} --- !u!33 &2083699544 @@ -6102,6 +6206,34 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 120185325598694946, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: m_Size.x + value: 2.4947968 + objectReference: {fileID: 0} + - target: {fileID: 120185325598694946, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: m_Size.y + value: 5.5596495 + objectReference: {fileID: 0} + - target: {fileID: 120185325598694946, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: m_Size.z + value: 9.845033 + objectReference: {fileID: 0} + - target: {fileID: 120185325598694946, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: m_Center.x + value: 0.2150624 + objectReference: {fileID: 0} + - target: {fileID: 120185325598694946, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: m_Center.y + value: -0.08873049 + objectReference: {fileID: 0} + - target: {fileID: 120185325598694946, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: m_Center.z + value: -4.3667126 + objectReference: {fileID: 0} + - target: {fileID: 3129800592749546633, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: m_LocalPosition.y + value: 0.115 + objectReference: {fileID: 0} - target: {fileID: 3129800593820501904, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} propertyPath: m_Name value: Spot @@ -6112,31 +6244,31 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 3129800593820501905, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} propertyPath: m_LocalPosition.x - value: 2.79 + value: 6.71 objectReference: {fileID: 0} - target: {fileID: 3129800593820501905, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} propertyPath: m_LocalPosition.y - value: 2.84 + value: 2.162 objectReference: {fileID: 0} - target: {fileID: 3129800593820501905, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} propertyPath: m_LocalPosition.z - value: 4.04 + value: 28.13 objectReference: {fileID: 0} - target: {fileID: 3129800593820501905, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} propertyPath: m_LocalRotation.w - value: 1 + value: 0.71455836 objectReference: {fileID: 0} - target: {fileID: 3129800593820501905, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} propertyPath: m_LocalRotation.x - value: 0 + value: -0 objectReference: {fileID: 0} - target: {fileID: 3129800593820501905, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} propertyPath: m_LocalRotation.y - value: 0 + value: -0.6995759 objectReference: {fileID: 0} - target: {fileID: 3129800593820501905, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} propertyPath: m_LocalRotation.z - value: 0 + value: -0 objectReference: {fileID: 0} - target: {fileID: 3129800593820501905, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} propertyPath: m_LocalEulerAnglesHint.x @@ -6144,7 +6276,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 3129800593820501905, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} propertyPath: m_LocalEulerAnglesHint.y - value: 0 + value: -88.786 objectReference: {fileID: 0} - target: {fileID: 3129800593820501905, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} propertyPath: m_LocalEulerAnglesHint.z @@ -6170,6 +6302,58 @@ PrefabInstance: propertyPath: interactSound value: objectReference: {fileID: 8300000, guid: bd73a052a46b6b441805c014632fd1ea, type: 3} + - target: {fileID: 3129800593820501910, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: wheels.Array.size + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3129800593820501910, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: wheels.Array.data[0] + value: + objectReference: {fileID: 1306672502} + - target: {fileID: 3129800593820501910, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: wheels.Array.data[1] + value: + objectReference: {fileID: 2035943281} + - target: {fileID: 3129800593820501910, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: wheels.Array.data[2] + value: + objectReference: {fileID: 399020193} + - target: {fileID: 3129800593820501910, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: wheels.Array.data[3] + value: + objectReference: {fileID: 1091839670} + - target: {fileID: 3129800593820501910, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: wheels.Array.data[4] + value: + objectReference: {fileID: 1937114486} + - target: {fileID: 3129800593820501910, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: wheels.Array.data[5] + value: + objectReference: {fileID: 552528065} + - target: {fileID: 7964177783503292765, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: m_LocalPosition.z + value: 1.342 + objectReference: {fileID: 0} + - target: {fileID: 8531514674641296185, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: m_Size.y + value: 2.3579059 + objectReference: {fileID: 0} + - target: {fileID: 8531514674641296185, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: m_Size.z + value: 2.3862565 + objectReference: {fileID: 0} + - target: {fileID: 8531514674641296185, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: m_Center.y + value: 0.79525137 + objectReference: {fileID: 0} + - target: {fileID: 8531514674641296185, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: m_Center.z + value: 0.07651794 + objectReference: {fileID: 0} + - target: {fileID: 8531514674641296185, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} + propertyPath: m_IsTrigger + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: c8ee16aeadb4789418878c77a39029fd, type: 3} --- !u!4 &3129800594024812083 stripped diff --git a/Assets/Prefabs/Spot.prefab b/Assets/Prefabs/Spot.prefab index 96fd1f3..8e69758 100644 --- a/Assets/Prefabs/Spot.prefab +++ b/Assets/Prefabs/Spot.prefab @@ -176,6 +176,7 @@ GameObject: m_Component: - component: {fileID: 3129800593820501905} - component: {fileID: 3129800593820501910} + - component: {fileID: 8531514674641296185} m_Layer: 0 m_Name: Spot m_TagString: Untagged @@ -215,13 +216,34 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: sphere: {fileID: 3129800592749546628} - visor: {fileID: 0} + visor: {fileID: 5734351610328079135} + detector: {fileID: 0} + wheels: + - {fileID: 431178397659895055} + - {fileID: 4712379551056951868} + - {fileID: 1570633890004696089} + - {fileID: 5764007707003976729} + - {fileID: 4391365009072602997} + - {fileID: 1269607093256655120} backgroundSource: {fileID: 2726613540516421944} sfxSource: {fileID: 2119513593295372362} interactSource: {fileID: 2084694431337102608} idleSound: {fileID: 8300000, guid: 03bf883391d278b4d865ea9ef483ea2c, type: 3} interactSound: {fileID: 8300000, guid: bd73a052a46b6b441805c014632fd1ea, type: 3} moveClip: {fileID: 8300000, guid: 5c33895e0bb8014479d8f62314b03c98, type: 3} +--- !u!65 &8531514674641296185 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3129800593820501904} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1.1244004, y: 2.419658, z: 2.7789826} + m_Center: {x: -0.018619657, y: 0.8261274, z: 0.015185595} --- !u!1 &4501560709180593753 GameObject: m_ObjectHideFlags: 0 @@ -550,3 +572,38 @@ Transform: m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: da042d7a353595c48b39df8083bfe8a8, type: 3} m_PrefabInstance: {fileID: 3982011027894835983} m_PrefabAsset: {fileID: 0} +--- !u!1 &5734351610328079135 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: -516098083770646512, guid: da042d7a353595c48b39df8083bfe8a8, type: 3} + m_PrefabInstance: {fileID: 3982011027894835983} + m_PrefabAsset: {fileID: 0} +--- !u!1 &431178397659895055 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: -5568371526223589888, guid: da042d7a353595c48b39df8083bfe8a8, type: 3} + m_PrefabInstance: {fileID: 3982011027894835983} + m_PrefabAsset: {fileID: 0} +--- !u!1 &4712379551056951868 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 8513859187771203891, guid: da042d7a353595c48b39df8083bfe8a8, type: 3} + m_PrefabInstance: {fileID: 3982011027894835983} + m_PrefabAsset: {fileID: 0} +--- !u!1 &1570633890004696089 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: -6733177361254619370, guid: da042d7a353595c48b39df8083bfe8a8, type: 3} + m_PrefabInstance: {fileID: 3982011027894835983} + m_PrefabAsset: {fileID: 0} +--- !u!1 &5764007707003976729 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 8700725330082129686, guid: da042d7a353595c48b39df8083bfe8a8, type: 3} + m_PrefabInstance: {fileID: 3982011027894835983} + m_PrefabAsset: {fileID: 0} +--- !u!1 &4391365009072602997 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: -8380157826906577798, guid: da042d7a353595c48b39df8083bfe8a8, type: 3} + m_PrefabInstance: {fileID: 3982011027894835983} + m_PrefabAsset: {fileID: 0} +--- !u!1 &1269607093256655120 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 2800250516343163423, guid: da042d7a353595c48b39df8083bfe8a8, type: 3} + m_PrefabInstance: {fileID: 3982011027894835983} + m_PrefabAsset: {fileID: 0} diff --git a/Assets/SpotController.cs b/Assets/SpotController.cs index c810967..ccbb4bf 100644 --- a/Assets/SpotController.cs +++ b/Assets/SpotController.cs @@ -7,6 +7,8 @@ public class SpotController : MonoBehaviour public GameObject sphere; public GameObject visor; + public GameObject[] wheels; + public AudioSource backgroundSource; public AudioSource sfxSource; public AudioSource interactSource; @@ -21,9 +23,10 @@ public class SpotController : MonoBehaviour private float moveInput; private float turnInput; - private float turnSpeed = 50f; + private float turnSpeed = 150f; private Light light; + private bool blocked = false; private void Start() { @@ -43,12 +46,37 @@ public class SpotController : MonoBehaviour turnInput = Input.GetAxisRaw("Horizontal"); moveInput *= moveInput > 0 ? speed : revSpeed; + + if (moveInput != 0 && wheels.Length > 0) + { + for (int i = 0; i < wheels.Length; i++) + { + wheels[i].transform.Rotate(0, 0, moveInput / 60 * 360 * Time.deltaTime); + } + } ; float newRotation = turnInput * turnSpeed * Time.deltaTime * Input.GetAxisRaw("Vertical"); sphere.transform.Rotate(0, newRotation, 0, Space.Self); transform.position = sphere.transform.position; transform.rotation = sphere.transform.rotation; + + RaycastHit hit; + if (Physics.Raycast(transform.position, transform.forward, out hit, 1)) + { + if (hit.transform.tag == "Wall") + { + blocked = true; + } + else + { + blocked = false; + } + } + else + { + blocked = false; + } } IEnumerator FlashRoutine() @@ -64,7 +92,6 @@ public class SpotController : MonoBehaviour renderer.material.SetColor("_EmissionColor", Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f)); } } - private void LateUpdate() { if (moveInput != 0) @@ -80,6 +107,7 @@ public class SpotController : MonoBehaviour sfxSource.Stop(); } - sphere.transform.Translate(Vector3.forward * moveInput * Time.deltaTime, Space.Self); + if (!blocked && moveInput > 0) + sphere.transform.Translate(Vector3.forward * moveInput * Time.deltaTime, Space.Self); } } diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 1c92a78..0e4af85 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -3,7 +3,9 @@ --- !u!78 &1 TagManager: serializedVersion: 2 - tags: [] + tags: + - CinemachineTarget + - Wall layers: - Default - TransparentFX