From 709aad20f0e25b6f71ced315c34496d692cf4f49 Mon Sep 17 00:00:00 2001 From: louishorlaville Date: Mon, 24 Oct 2022 22:04:08 -0400 Subject: [PATCH 1/2] Added Speed Control to CharacterMovement --- .../Physics Material/Player.physicMaterial | 2 +- Assets/Prefabs/Player.prefab | 2 ++ Assets/Scenes/Dev.unity | 27 +++++++++++++++++ Assets/Scripts/CharacterMovement.cs | 29 +++++++++++++++++-- Assets/Scripts/GrappleHook.cs | 5 ++++ 5 files changed, 61 insertions(+), 4 deletions(-) diff --git a/Assets/Material/Physics Material/Player.physicMaterial b/Assets/Material/Physics Material/Player.physicMaterial index 576eaf8..5fd5d7d 100644 --- a/Assets/Material/Physics Material/Player.physicMaterial +++ b/Assets/Material/Physics Material/Player.physicMaterial @@ -9,6 +9,6 @@ PhysicMaterial: m_Name: Player dynamicFriction: 0 staticFriction: 0 - bounciness: 1 + bounciness: 0.7 frictionCombine: 0 bounceCombine: 0 diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index 29c931a..10e1370 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -275,12 +275,14 @@ MonoBehaviour: canWalk: 1 canJump: 1 movementSpeed: 0.8 + maxMovementSpeed: 20 jumpPower: 3 afterJumpHorizontalSlowdownTime: 1 groundDrag: 1 airDrag: 0 playerHeight: 0.6 jumpAirSlowdown: 80 + grappleHook: {fileID: 1772573266731274173} isGrounded: 0 --- !u!114 &8474203461765366282 MonoBehaviour: diff --git a/Assets/Scenes/Dev.unity b/Assets/Scenes/Dev.unity index 3b93fdf..6a16e7d 100644 --- a/Assets/Scenes/Dev.unity +++ b/Assets/Scenes/Dev.unity @@ -1961,6 +1961,16 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 1772573266731274163, guid: 4dbf735f9da7b9f43b69f1577e4e5763, + type: 3} + propertyPath: grappleHook + value: + objectReference: {fileID: 1341139412} + - target: {fileID: 1772573266731274163, guid: 4dbf735f9da7b9f43b69f1577e4e5763, + type: 3} + propertyPath: maxMovementSpeed + value: 20 + objectReference: {fileID: 0} - target: {fileID: 1772573266731274171, guid: 4dbf735f9da7b9f43b69f1577e4e5763, type: 3} propertyPath: m_Name @@ -1976,6 +1986,11 @@ PrefabInstance: propertyPath: hitMarkerRect value: objectReference: {fileID: 1301531513} + - target: {fileID: 1772573266731274174, guid: 4dbf735f9da7b9f43b69f1577e4e5763, + type: 3} + propertyPath: m_Constraints + value: 88 + objectReference: {fileID: 0} - target: {fileID: 1772573266731274175, guid: 4dbf735f9da7b9f43b69f1577e4e5763, type: 3} propertyPath: m_RootOrder @@ -2039,6 +2054,18 @@ Transform: type: 3} m_PrefabInstance: {fileID: 1341139406} m_PrefabAsset: {fileID: 0} +--- !u!114 &1341139412 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 1772573266731274173, guid: 4dbf735f9da7b9f43b69f1577e4e5763, + type: 3} + m_PrefabInstance: {fileID: 1341139406} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f45bd04209bb424e8b1f5271cb16ab0, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1530935835 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/CharacterMovement.cs b/Assets/Scripts/CharacterMovement.cs index e7a0245..411b25c 100644 --- a/Assets/Scripts/CharacterMovement.cs +++ b/Assets/Scripts/CharacterMovement.cs @@ -13,6 +13,7 @@ public class CharacterMovement : MonoBehaviour [Header("Movement settings")] [SerializeField] private float movementSpeed; + [SerializeField] private float maxMovementSpeed; [SerializeField] private float jumpPower; [SerializeField] private float afterJumpHorizontalSlowdownTime; @@ -21,6 +22,7 @@ public class CharacterMovement : MonoBehaviour [SerializeField] private float airDrag; [SerializeField] private float playerHeight; [SerializeField] private float jumpAirSlowdown; + [SerializeField] private GrappleHook grappleHook; public bool isGrounded; private bool isStunned = false; @@ -47,6 +49,7 @@ public class CharacterMovement : MonoBehaviour stopWalk = false; } + SpeedControl(); } private void FixedUpdate() @@ -117,11 +120,31 @@ public class CharacterMovement : MonoBehaviour float inputMovement = value.ReadValue(); rb.velocity = new Vector3(rb.velocity.x, jumpPower * inputMovement, rb.velocity.z); //rawInputMovement = new Vector3(rawInputMovement.x, jumpPower, rawInputMovement.z); - if (inputMovement == 1f) + } + } + + private void SpeedControl() + { + if (grappleHook.isGrappled()) + { + Vector3 flatVel = rb.velocity; + + if (flatVel.magnitude > maxMovementSpeed) { - Debug.Log("start jump"); + Vector3 limitedVel = flatVel.normalized * maxMovementSpeed; + rb.velocity = limitedVel; } } - + else + { + Vector3 flatVel = new Vector3(rb.velocity.x, 0f, rb.velocity.z); + + if (flatVel.magnitude > maxMovementSpeed) + { + Vector3 limitedVel = flatVel.normalized * maxMovementSpeed; + rb.velocity = new Vector3(limitedVel.x, rb.velocity.y, limitedVel.z); + } + } + } } diff --git a/Assets/Scripts/GrappleHook.cs b/Assets/Scripts/GrappleHook.cs index 0237eeb..90e1d34 100644 --- a/Assets/Scripts/GrappleHook.cs +++ b/Assets/Scripts/GrappleHook.cs @@ -44,6 +44,11 @@ public class GrappleHook : MonoBehaviour private Vector3 currGrappleEndPos; private GameObject hookedTo; // The obj we are hooked to public GameObject HookedTo{get => hookedTo; set => hookedTo = value;} + + public bool isGrappled() + { + return grappled; + } #region private methods void Start() From 4f049341ae62b8135cc8a91ffddad5c56bd5cb4f Mon Sep 17 00:00:00 2001 From: louishorlaville Date: Mon, 24 Oct 2022 22:51:57 -0400 Subject: [PATCH 2/2] Reduced movement speed Player --- Assets/Prefabs/Player.prefab | 2 +- Assets/Scripts/CharacterMovement.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index 10e1370..b057b38 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -274,7 +274,7 @@ MonoBehaviour: rb: {fileID: 1772573266731274174} canWalk: 1 canJump: 1 - movementSpeed: 0.8 + movementSpeed: 0.3 maxMovementSpeed: 20 jumpPower: 3 afterJumpHorizontalSlowdownTime: 1 diff --git a/Assets/Scripts/CharacterMovement.cs b/Assets/Scripts/CharacterMovement.cs index 411b25c..8244978 100644 --- a/Assets/Scripts/CharacterMovement.cs +++ b/Assets/Scripts/CharacterMovement.cs @@ -145,6 +145,5 @@ public class CharacterMovement : MonoBehaviour rb.velocity = new Vector3(limitedVel.x, rb.velocity.y, limitedVel.z); } } - } }