From 4e9e9880346c2f9ae01539288b64096b27ce14a9 Mon Sep 17 00:00:00 2001 From: Arlo Date: Tue, 30 Apr 2024 17:14:05 +0100 Subject: [PATCH] Feature: Enemy collision detection, and customisable keybinds Added: - Enemy collision detection - Customisable movement keybinds - Simplified movement code --- .vscode/settings.json | 2 +- Assets/Scenes/SampleScene.unity | 113 ++---------------- Assets/Scripts/PlayerController.cs | 52 ++++++++ ...ement.cs.meta => PlayerController.cs.meta} | 0 Assets/Scripts/PlayerMovement.cs | 44 ------- .../Standard/Prototype_512x512_Grey2.mat | 11 +- 6 files changed, 71 insertions(+), 151 deletions(-) create mode 100644 Assets/Scripts/PlayerController.cs rename Assets/Scripts/{PlayerMovement.cs.meta => PlayerController.cs.meta} (100%) delete mode 100644 Assets/Scripts/PlayerMovement.cs diff --git a/.vscode/settings.json b/.vscode/settings.json index e220109..0da7f5e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -56,5 +56,5 @@ "temp/": true, "Temp/": true }, - "dotnet.defaultSolution": "Mini-Games-Games.sln" + "dotnet.defaultSolution": "Mini-Games-Game.sln" } \ No newline at end of file diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index c2f2e4e..48471b3 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 705507994} - m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1} + m_IndirectSpecularColor: {r: 0.18028326, g: 0.22571333, b: 0.30692202, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -123,103 +123,6 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} ---- !u!1 &84224833 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 84224837} - - component: {fileID: 84224836} - - component: {fileID: 84224835} - - component: {fileID: 84224834} - m_Layer: 0 - m_Name: Boobies - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!65 &84224834 -BoxCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 84224833} - 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!23 &84224835 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 84224833} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_StaticShadowCaster: 0 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - 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 - m_AdditionalVertexStreams: {fileID: 0} ---- !u!33 &84224836 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 84224833} - m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} ---- !u!4 &84224837 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 84224833} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.027415752, y: 0.95, z: -0.016391277} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 5 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &441602406 GameObject: m_ObjectHideFlags: 0 @@ -233,7 +136,7 @@ GameObject: - component: {fileID: 441602408} - component: {fileID: 441602407} m_Layer: 0 - m_Name: Plane + m_Name: Ground m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -312,7 +215,7 @@ Transform: m_GameObject: {fileID: 441602406} 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_LocalScale: {x: 5, y: 5, z: 5} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} @@ -508,10 +411,10 @@ GameObject: - component: {fileID: 1261174832} - component: {fileID: 1261174831} - component: {fileID: 1261174830} - - component: {fileID: 1261174829} - component: {fileID: 1261174834} + - component: {fileID: 1261174829} m_Layer: 0 - m_Name: Cube + m_Name: Player m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -537,7 +440,11 @@ MonoBehaviour: rb: {fileID: 1261174834} drag: 3 orientation: {fileID: 1261174833} - speed: {x: 0, y: 0, z: 0} + speed: 5 + forwardKey: 44 + backwardKey: 111 + leftKey: 97 + rightKey: 101 --- !u!65 &1261174830 BoxCollider: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs new file mode 100644 index 0000000..7c687d3 --- /dev/null +++ b/Assets/Scripts/PlayerController.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using UnityEngine; + +public class PlayerController : MonoBehaviour +{ + [Header("Keybinds")] + public KeyCode forwardKey = KeyCode.W; + public KeyCode backwardKey = KeyCode.S; + public KeyCode leftKey = KeyCode.A; + public KeyCode rightKey = KeyCode.D; + + [Header("Speed")] + public float speed = 5; + + [Header("Player Object")] + public Vector3 moveDirection; + public Rigidbody rb; + + + void Start() + { + rb = GetComponent(); + rb.freezeRotation = true; + } + + void Update() + { + moveDirection = PlayerInput(); + + rb.velocity = moveDirection.normalized * speed; + } + + Vector3 PlayerInput() + { + float forward = Convert.ToSingle(Input.GetKey(forwardKey)); + float backward = Convert.ToSingle(Input.GetKey(backwardKey)); + float right = Convert.ToSingle(Input.GetKey(rightKey)); + float left = Convert.ToSingle(Input.GetKey(leftKey)); + return new Vector3(right - left, 0, forward - backward); + } + + void OnCollisionEnter(Collision collision) + { + if (collision.gameObject.name == "Enemy") + { + Debug.Log("OWIE"); + } + } +} diff --git a/Assets/Scripts/PlayerMovement.cs.meta b/Assets/Scripts/PlayerController.cs.meta similarity index 100% rename from Assets/Scripts/PlayerMovement.cs.meta rename to Assets/Scripts/PlayerController.cs.meta diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs deleted file mode 100644 index 6dbd25e..0000000 --- a/Assets/Scripts/PlayerMovement.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class PlayerMovement : MonoBehaviour -{ - [Header("Speed")] - public float acceleration; - public float maxSpeed; - - [Header("Movement")] - public float horizontalInput; - public float verticalInput; - public Vector3 moveDirection; - public Rigidbody rb; - public float drag; - public Transform orientation; - public Vector3 speed; - - void Start() - { - rb = GetComponent(); - rb.freezeRotation = true; - rb.drag = drag; - speed = new Vector3(0f, 0f, 0f); - } - - void Update() - { - horizontalInput = Input.GetAxisRaw("Horizontal"); - verticalInput = Input.GetAxisRaw("Vertical"); - moveDirection = orientation.forward * verticalInput + orientation.up * 0 + orientation.right * horizontalInput; - moveDirection = moveDirection.normalized * acceleration; - - rb.AddForce(moveDirection); - - if (rb.velocity.magnitude > maxSpeed) - { - rb.velocity = rb.velocity.normalized * maxSpeed; - } - // rb.velocity.Set(Vector3.ClampMagnitude(moveDirection, maxSpeed)); - speed.Set(rb.velocity.x, rb.velocity.magnitude, rb.velocity.y); - } -} diff --git a/Assets/Thirdparty/Ciathyza/Gridbox Prototype Materials/Materials/Standard/Prototype_512x512_Grey2.mat b/Assets/Thirdparty/Ciathyza/Gridbox Prototype Materials/Materials/Standard/Prototype_512x512_Grey2.mat index 627867f..b4054cc 100644 --- a/Assets/Thirdparty/Ciathyza/Gridbox Prototype Materials/Materials/Standard/Prototype_512x512_Grey2.mat +++ b/Assets/Thirdparty/Ciathyza/Gridbox Prototype Materials/Materials/Standard/Prototype_512x512_Grey2.mat @@ -15,15 +15,19 @@ MonoBehaviour: version: 11 --- !u!21 &2100000 Material: - serializedVersion: 6 + serializedVersion: 8 m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: Prototype_512x512_Grey2 m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} - m_ShaderKeywords: _DISABLE_SSR_TRANSPARENT _NORMALMAP _NORMALMAP_TANGENT_SPACE - _SPECULARHIGHLIGHTS_OFF + m_ValidKeywords: + - _NORMALMAP + - _SPECULARHIGHLIGHTS_OFF + m_InvalidKeywords: + - _DISABLE_SSR_TRANSPARENT + - _NORMALMAP_TANGENT_SPACE m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 @@ -175,6 +179,7 @@ Material: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} m_Offset: {x: 0, y: 0} + m_Ints: [] m_Floats: - _AORemapMax: 1 - _AORemapMin: 0