From c881e37b9cfeaef8b53cec931b86f43fffb7f55c Mon Sep 17 00:00:00 2001 From: Melbyj1125 <60886701+Melbyj1125@users.noreply.github.com> Date: Sun, 9 Jan 2022 08:12:14 -0600 Subject: [PATCH] Made some small improvements to wallrun and the player prefabs Grapple movement is a lot better just need to implement momentum --- .../Prefabs/Player/DebugPlayerPrefab.prefab | 12 +- Assets/Prefabs/Player/PlayerPrefab.prefab | 4 +- Assets/Scenes/Demos/MovementScene.unity | 180 ++++++++++-------- .../DebugPlayer/DebugItems/dGrapplingHook.cs | 35 +++- .../DebugPlayer/DebugItems/dWallRun.cs | 2 +- .../DebugPlayer/dPlayerMovement.cs | 12 +- UserSettings/EditorUserSettings.asset | 8 +- 7 files changed, 151 insertions(+), 102 deletions(-) diff --git a/Assets/Prefabs/Player/DebugPlayerPrefab.prefab b/Assets/Prefabs/Player/DebugPlayerPrefab.prefab index ca787e9..7866e8d 100644 --- a/Assets/Prefabs/Player/DebugPlayerPrefab.prefab +++ b/Assets/Prefabs/Player/DebugPlayerPrefab.prefab @@ -27,7 +27,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2556153648277679257} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -2, y: 2.85, z: -4} + m_LocalPosition: {x: 0, y: 4.5, z: -7} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 6926740475113451123} @@ -230,7 +230,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3607330906377400225} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -2.12, y: 1.25, z: 0} + m_LocalPosition: {x: 0, y: 3.15, z: -4} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 2731864384567516644} @@ -299,7 +299,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: maxVel: 40 - minVel: 20 + minVel: 15 curVel: 0 acc: 0.01 jumpPow: 60 @@ -441,8 +441,8 @@ MonoBehaviour: vel: {x: 0, y: 0, z: 0} driftVel: {x: 0, y: 0, z: 0} curJumpNum: 0 - lowJumpMultiplier: 0.3 - fallMultiplier: 1.5 + lowJumpMultiplier: 0.1 + fallMultiplier: 1.6 g: 0 isGrounded: 0 groundCheckDistance: 0.05 @@ -509,7 +509,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: f4264f4f7bed1d7499a037436582ed17, type: 3} m_Name: m_EditorClassIdentifier: - wallMaxDistance: 0.8 + wallMaxDistance: 1 wallSpeedMultiplier: 1.2 minimumHeight: 0.1 maxAngleRoll: 20 diff --git a/Assets/Prefabs/Player/PlayerPrefab.prefab b/Assets/Prefabs/Player/PlayerPrefab.prefab index f36e1f7..ef6598c 100644 --- a/Assets/Prefabs/Player/PlayerPrefab.prefab +++ b/Assets/Prefabs/Player/PlayerPrefab.prefab @@ -39,7 +39,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4814433541978696327} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: 0, y: 3.15, z: -4} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 9039284905748829538} @@ -430,7 +430,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7188906082643956521} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 1.6, z: -4} + m_LocalPosition: {x: 0, y: 4.5, z: -8.7} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 7188906082087890177} diff --git a/Assets/Scenes/Demos/MovementScene.unity b/Assets/Scenes/Demos/MovementScene.unity index c63f16f..3235b7f 100644 --- a/Assets/Scenes/Demos/MovementScene.unity +++ b/Assets/Scenes/Demos/MovementScene.unity @@ -594,7 +594,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 8 + m_RootOrder: 7 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &724425600 GameObject: @@ -1211,7 +1211,7 @@ Transform: m_LocalScale: {x: 5, y: 1, z: 5} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 7 + m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!136 &1181153603 CapsuleCollider: @@ -1243,83 +1243,6 @@ Rigidbody: m_Interpolate: 0 m_Constraints: 0 m_CollisionDetection: 0 ---- !u!1001 &1212970163 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 1818923263116056088, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: wallMaxDistance - value: 3 - objectReference: {fileID: 0} - - target: {fileID: 5633209979457551608, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: m_Name - value: DebugPlayerPrefab - objectReference: {fileID: 0} - - target: {fileID: 6743056025486776975, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: fallMultiplier - value: 1.6 - objectReference: {fileID: 0} - - target: {fileID: 6743056025486776975, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: lowJumpMultiplier - value: 0.1 - objectReference: {fileID: 0} - - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: m_RootOrder - value: 4 - objectReference: {fileID: 0} - - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: m_LocalPosition.y - value: 57.5 - objectReference: {fileID: 0} - - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8100520363622627413, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: minVel - value: 15 - objectReference: {fileID: 0} - - target: {fileID: 8100520363622627413, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} - propertyPath: hasWallrun - value: 0 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} --- !u!1 &1257935739 GameObject: m_ObjectHideFlags: 0 @@ -1539,7 +1462,7 @@ SphereCollider: m_GameObject: {fileID: 1405946429} m_Material: {fileID: 0} m_IsTrigger: 0 - m_Enabled: 1 + m_Enabled: 0 serializedVersion: 2 m_Radius: 0.5 m_Center: {x: 0, y: 0, z: 0} @@ -1604,7 +1527,7 @@ Transform: m_LocalScale: {x: 10, y: 10, z: 10} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 6 + m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!54 &1405946434 Rigidbody: @@ -1757,6 +1680,99 @@ MeshFilter: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1650963652} m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!1001 &1730158536 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 5633209979457551608, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_Name + value: DebugPlayerPrefab + objectReference: {fileID: 0} + - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_RootOrder + value: 8 + objectReference: {fileID: 0} + - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalPosition.y + value: 3.3 + objectReference: {fileID: 0} + - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6926740475113451123, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8100520363622627413, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: hasGrapple + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 8720404377688450390, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 8720404377688450390, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8720404377688450390, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8720404377688450390, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8720404377688450390, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8720404377688450390, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 9156062931443001395, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalPosition.y + value: 4.6 + objectReference: {fileID: 0} + - target: {fileID: 9156062931443001395, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} + propertyPath: m_LocalPosition.z + value: -8.7 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 362ca97b75c291a47ab81d628a81f440, type: 3} --- !u!1 &1806935633 GameObject: m_ObjectHideFlags: 0 @@ -1987,7 +2003,7 @@ PrefabInstance: m_Modifications: - target: {fileID: 6150409029086178024, guid: b95800967feee2a46a6c25838eb2fc6c, type: 3} propertyPath: m_RootOrder - value: 5 + value: 4 objectReference: {fileID: 0} - target: {fileID: 6150409029086178024, guid: b95800967feee2a46a6c25838eb2fc6c, type: 3} propertyPath: m_LocalScale.x diff --git a/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs b/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs index 0a7b75a..150255c 100644 --- a/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs +++ b/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs @@ -18,12 +18,15 @@ public class dGrapplingHook : NetworkBehaviour private PlayerStats pStats; [SerializeField] private float ropeLength; private float climbRate = 5; + private Vector3 swingDirection; + private float swingSpeed = 90; Vector3 tensionDirection; Vector3 pendulumSideDirection; Vector3 tangentDirection; float tensionForce; public Vector3 forceDirection; + private bool unhooking = false; // Start is called before the first frame update @@ -51,11 +54,11 @@ public class dGrapplingHook : NetworkBehaviour hookPoint = hookPoints[hookPointIndex]; //The point we are grappling from ropeLength = Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) + 0.5f; isGrappled = true; //toggle grappling state + unhooking = false; } } else //Else we are grappling { - //physics tear down? isGrappled = false; //toggle grappling state to release } } @@ -89,12 +92,19 @@ public class dGrapplingHook : NetworkBehaviour //Do grappling physics based on hookPoint if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) > ropeLength ) { - //Impact Based + forceDirection = calculateForceDirection(1, playerMovement.g, hookPoint.transform.position); } + movementController.Move(swingMoveController()); + } + else if(!isGrappled && !unhooking){ + this.gameObject.transform.localEulerAngles = new Vector3(0, 0, 0); + unhooking = true; } if(playerMovement.GetJumpPressed()) isGrappled = false; + + if(isGrappled == false) forceDirection = Vector3.zero; } int FindHookPoint() @@ -114,17 +124,30 @@ public class dGrapplingHook : NetworkBehaviour Vector3 calculateForceDirection(float mass, float g, Vector3 hPoint){ tensionDirection = (hPoint - transform.position).normalized; - Debug.Log(tensionDirection); float inclinationAngle = Vector3.Angle(transform.position - hPoint, -transform.up); - tensionForce = mass * -g * Mathf.Cos(Mathf.Deg2Rad * inclinationAngle); - Debug.Log(g); Vector3 fDirection = tensionDirection * tensionForce; - Debug.Log(fDirection); return fDirection; } + + Vector3 swingMoveController(){ + + float inputVert = Input.GetAxis("Vertical"); + float inputHor = Input.GetAxis("Horizontal"); + + if((!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S))) inputVert = 0; + + if((!Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))) inputHor = 0; + + //Movement Vector for the player to move in + swingDirection = Vector3.Cross(tensionDirection, ((transform.right * -inputVert) + (transform.forward * inputHor))).normalized; + //Actual swing movement vector with speed applied + Vector3 swingMovement = (swingDirection * Time.deltaTime * swingSpeed); + + return (swingMovement); + } } diff --git a/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dWallRun.cs b/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dWallRun.cs index 0750a5d..d941f4e 100644 --- a/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dWallRun.cs +++ b/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dWallRun.cs @@ -170,7 +170,7 @@ public class dWallRun : NetworkBehaviour } moveToSet.y = 0; - + // playerMovementController.SetPlayerVelocity(moveToSet); isWallRunning = true; diff --git a/Assets/Scripts/PlayerScripts/DebugPlayer/dPlayerMovement.cs b/Assets/Scripts/PlayerScripts/DebugPlayer/dPlayerMovement.cs index c489ec6..d294986 100644 --- a/Assets/Scripts/PlayerScripts/DebugPlayer/dPlayerMovement.cs +++ b/Assets/Scripts/PlayerScripts/DebugPlayer/dPlayerMovement.cs @@ -33,7 +33,10 @@ public class dPlayerMovement : NetworkBehaviour float curCoyJumpTimer; // current Coyote Jump time public float lowJumpMultiplier; // Short jump multiplier public float fallMultiplier; // High Jump Multiplier - public float g = 0; // the y velocity + + //Gravity values + public float g = 0; // the y velocity affected by player Grav + private float maxG = -100; //The max downwards y velocity or g the player can have //Glide Values bool tempSet = false; @@ -89,6 +92,7 @@ public class dPlayerMovement : NetworkBehaviour //Blink private dBlink blink; + //Grapple private dGrapplingHook grapple; @@ -190,6 +194,7 @@ public class dPlayerMovement : NetworkBehaviour vel = moveX + moveZ; Vector3 moveXZ = new Vector3(vel.x, 0, vel.z); driftVel = Vector3.Lerp(driftVel, moveXZ, pStats.Traction * Time.deltaTime); + if(grapple.isGrappled) driftVel = Vector3.zero; //Gravity and Jump calculations UpdateGravity(); @@ -458,6 +463,11 @@ public class dPlayerMovement : NetworkBehaviour else{ g = 0; } + + //Caps out the players downwards speed + if(g < maxG){ + g = maxG; + } } diff --git a/UserSettings/EditorUserSettings.asset b/UserSettings/EditorUserSettings.asset index 13ef6bd..6f16979 100644 --- a/UserSettings/EditorUserSettings.asset +++ b/UserSettings/EditorUserSettings.asset @@ -9,14 +9,14 @@ EditorUserSettings: value: 22424703114646680e0b0227036c731f1415016439262f2434 flags: 0 RecentlyUsedScenePath-1: - value: 22424703114646680e0b0227036c7b151b180b6501273035202c1327d1e33136e7a923e7ee2e26 - flags: 0 - RecentlyUsedScenePath-2: value: 22424703114646680e0b0227036c78111b125507233d28242c20137df7ee3d2cfb flags: 0 - RecentlyUsedScenePath-3: + RecentlyUsedScenePath-2: value: 22424703114646680e0b0227036c6f02131b172b282d347e38271427fb flags: 0 + RecentlyUsedScenePath-3: + value: 22424703114646680e0b0227036c7b151b180b6501273035202c1327d1e33136e7a923e7ee2e26 + flags: 0 vcSharedLogLevel: value: 0d5e400f0650 flags: 0