From f1db8041557d21643d46cc580e3b3a86402785d4 Mon Sep 17 00:00:00 2001 From: Gregory Campbell Date: Sat, 21 Dec 2019 23:17:24 -0500 Subject: [PATCH 1/2] Implemented basic wallrunning --- Assets/Scenes/Test Scene.unity | 4 ++-- Assets/Scripts/PlayerController.cs | 15 +++++++++++++++ ProjectSettings/TagManager.asset | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Assets/Scenes/Test Scene.unity b/Assets/Scenes/Test Scene.unity index 7b56c45..f1b7a93 100644 --- a/Assets/Scenes/Test Scene.unity +++ b/Assets/Scenes/Test Scene.unity @@ -167,7 +167,7 @@ GameObject: - component: {fileID: 194035205} m_Layer: 0 m_Name: Running Wall Left - m_TagString: Environment + m_TagString: Wall m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -1391,7 +1391,7 @@ GameObject: - component: {fileID: 858957127} m_Layer: 0 m_Name: Running Wall Right - m_TagString: Environment + m_TagString: Wall m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 42080f9..6baae1b 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -45,6 +45,16 @@ public class PlayerController : MonoBehaviour maxSpeedStore = maxSpeed; } + void OnControllerColliderHit(ControllerColliderHit hit) + { + + if(hit.gameObject.tag == "Wall") + { + gravity = 0.5f; + } + + } + void Update() { @@ -133,6 +143,11 @@ public class PlayerController : MonoBehaviour jump++; } + if (characterController.collisionFlags == CollisionFlags.None) + { + gravity = 5; + } + moveDirection.y += Physics.gravity.y * gravity * Time.deltaTime; velocity = Vector3.ClampMagnitude(velocity, maxSpeed); diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 2f78719..3d6800d 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -5,6 +5,7 @@ TagManager: serializedVersion: 2 tags: - Environment + - Wall layers: - Default - TransparentFX From 9818b32bdca9811e38b9308c66035dd0d5ecb30d Mon Sep 17 00:00:00 2001 From: Gregory Campbell Date: Tue, 31 Dec 2019 18:17:35 -0500 Subject: [PATCH 2/2] Got a functional implementation of wall running that I am satisfied with --- Assets/Scenes/Test Scene.unity | 16 +++++++------- Assets/Scripts/PlayerController.cs | 34 ++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Assets/Scenes/Test Scene.unity b/Assets/Scenes/Test Scene.unity index f1b7a93..4c85e36 100644 --- a/Assets/Scenes/Test Scene.unity +++ b/Assets/Scenes/Test Scene.unity @@ -180,8 +180,8 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 194035203} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 62, y: 6.5, z: 12} - m_LocalScale: {x: 25, y: 20, z: 0.25} + m_LocalPosition: {x: 80, y: 6.5, z: 12} + m_LocalScale: {x: 75, y: 20, z: 0.25} m_Children: [] m_Father: {fileID: 1013482115} m_RootOrder: 0 @@ -366,7 +366,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 203887784} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 84, y: -0.5, z: 6} + m_LocalPosition: {x: 120, y: -0.5, z: 6} m_LocalScale: {x: 20, y: 0.5, z: 12} m_Children: [] m_Father: {fileID: 833538478} @@ -1205,7 +1205,7 @@ CapsuleCollider: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 741217452} m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_Enabled: 1 m_Radius: 0.5 m_Height: 2 @@ -1404,8 +1404,8 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 858957125} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 62, y: 6.5, z: 0} - m_LocalScale: {x: 25, y: 20, z: 0.25} + m_LocalPosition: {x: 80, y: 6.5, z: 0} + m_LocalScale: {x: 75, y: 20, z: 0.25} m_Children: [] m_Father: {fileID: 1013482115} m_RootOrder: 1 @@ -2045,8 +2045,8 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1853948297} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 62, y: -3.5, z: 6} - m_LocalScale: {x: 25, y: 0.25, z: 12} + m_LocalPosition: {x: 80, y: -3.5, z: 6} + m_LocalScale: {x: 75, y: 0.25, z: 12} m_Children: [] m_Father: {fileID: 833538478} m_RootOrder: 1 diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 6baae1b..1ff4613 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -22,7 +22,9 @@ public class PlayerController : MonoBehaviour public Transform pivot; public GameObject playerModel; + private bool wallRunning = false; private int jump = 0; + private int wall = 0; private float maxSpeedStore; private float capsuleHeight; private float controllerHeight; @@ -50,9 +52,10 @@ public class PlayerController : MonoBehaviour if(hit.gameObject.tag == "Wall") { - gravity = 0.5f; + wallRunning = true; + wall++; } - + } void Update() @@ -72,7 +75,7 @@ public class PlayerController : MonoBehaviour if (jump <= 1) { //moveDirection = moveDirection.normalized * speed; //Remove this line to make running diagonal the fastest standard run - maxSpeed = maxSpeedStore; + //maxSpeed = maxSpeedStore; } else { //moveDirection = (moveDirection.normalized * speed)/4; //Remove this line to make running diagonal the fastest standard run @@ -145,11 +148,34 @@ public class PlayerController : MonoBehaviour if (characterController.collisionFlags == CollisionFlags.None) { - gravity = 5; + wallRunning = false; + wall = 0; } moveDirection.y += Physics.gravity.y * gravity * Time.deltaTime; + if (wallRunning) + { + maxSpeed = maxSpeedStore*1.5f; + jump = 0; + + if(wall == 1) + { + startTime = Time.time; + } + + if(startTime + oneSec < Time.time) + { + + moveDirection.y += Physics.gravity.y * (gravity/8) * Time.deltaTime; + //wallRunning = false; + maxSpeed = maxSpeedStore; + + } else { + moveDirection.y = 0.0f; + } + } + velocity = Vector3.ClampMagnitude(velocity, maxSpeed); velocity.y = moveDirection.y;