diff --git a/Assets/Prefabs/Player/DebugPlayerPrefab 1.prefab b/Assets/Prefabs/Player/DebugPlayerPrefab 1.prefab index 10e9a68..52fb74f 100644 --- a/Assets/Prefabs/Player/DebugPlayerPrefab 1.prefab +++ b/Assets/Prefabs/Player/DebugPlayerPrefab 1.prefab @@ -3777,6 +3777,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: nitroItem: {fileID: 11400000, guid: b91f668477f6b3244b3fea3204e6cd87, type: 2} + isNitroing: 0 --- !u!1 &6716225286288627934 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Demos/MovementScene.unity b/Assets/Scenes/Demos/MovementScene.unity index 7727866..3099da3 100644 --- a/Assets/Scenes/Demos/MovementScene.unity +++ b/Assets/Scenes/Demos/MovementScene.unity @@ -1523,7 +1523,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1405946429} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -3.4, y: 18.3, z: 10.3} + m_LocalPosition: {x: 36.3, y: 24.5, z: 13.7} m_LocalScale: {x: 10, y: 10, z: 10} m_Children: [] m_Father: {fileID: 0} @@ -1605,12 +1605,16 @@ PrefabInstance: value: 1 objectReference: {fileID: 0} - target: {fileID: 6664667533527261801, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3} - propertyPath: hasGrapple + propertyPath: hasNitro value: 1 objectReference: {fileID: 0} + - target: {fileID: 6664667533527261801, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3} + propertyPath: hasGrapple + value: 0 + objectReference: {fileID: 0} - target: {fileID: 6664667533527261801, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3} propertyPath: hasWallrun - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 6664667533527262099, guid: 6adb8bcc65ee3a54da64d7c65225f219, type: 3} propertyPath: m_Enabled diff --git a/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dDash.cs b/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dDash.cs index a86762c..0f6a598 100644 --- a/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dDash.cs +++ b/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dDash.cs @@ -54,7 +54,7 @@ public class dDash : NetworkBehaviour{ private IEnumerator startCoolDown(){ Debug.Log("start corotine"); isOnCoolDown = true; - driver.startUICooldown(dashItem.name); + //driver.startUICooldown(dashItem.name); yield return new WaitForSeconds(dashItem.cooldownM); isOnCoolDown = false; Debug.Log("end corotine"); diff --git a/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs b/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs index 46eef12..7318c6e 100644 --- a/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs +++ b/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs @@ -172,7 +172,6 @@ public class dGrapplingHook : NetworkBehaviour swingback = true; release = false; } - Debug.Log(playerMovement.isGrounded); } //Finds the nearest hook to the player @@ -226,14 +225,14 @@ public class dGrapplingHook : NetworkBehaviour if(oldXZDir != curXZDir){ //midpointMom = swingMom; swingback = false; - Debug.Log("flip"); + //Debug.Log("flip"); } if(swingback == false && swingMom <= (oldSwingMom*(.75f))){ swingback = true; oldSwingMom = swingMom; oldXZDir = (new Vector3(hookPoint.transform.position.x,0,hookPoint.transform.position.z) - new Vector3(transform.position.x,0,transform.position.z)).normalized; - Debug.Log("swingback"); + //Debug.Log("swingback"); } curXZDir = (new Vector3(hPoint.x,0,hPoint.z) - new Vector3(transform.position.x,0,transform.position.z)).normalized; @@ -254,7 +253,6 @@ public class dGrapplingHook : NetworkBehaviour if(sMom > maxSwingMom){ sMom = maxSwingMom; } - Debug.Log(playerSpeed); return sMom; } diff --git a/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dNitro.cs b/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dNitro.cs index 3769b23..4d1deb0 100644 --- a/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dNitro.cs +++ b/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dNitro.cs @@ -8,7 +8,9 @@ public class dNitro : MonoBehaviour private PlayerStats playerStats; public SpecialItem nitroItem; private bool isOnCoolDown = false; - private bool isNitroing = false; + public bool isNitroing = false; + + private float tempTimer = 5; //this will need to be set from scritable object or something; // Start is called before the first frame update @@ -24,23 +26,40 @@ public class dNitro : MonoBehaviour //once cooldowns are implemented, put this on one (a long one) if (Input.GetKeyDown(KeyCode.LeftShift) && isOnCoolDown == false && playerStats.HasNitro) { - if(playerStats.CurVel < playerStats.HardCapMaxVel){ - playerStats.CurVel += playerStats.Acc * 10; - } - else if(playerStats.CurVel > playerStats.HardCapMaxVel){ - playerStats.CurVel = playerStats.HardCapMaxVel; - } + isNitroing = true; - StartCoroutine(startCoolDown()); + } + } + + void FixedUpdate(){ + if(isNitroing){ + if(tempTimer > 0){ + + tempTimer -= .04f; + + Debug.Log("nitro is on"); + + if(playerStats.CurVel < playerStats.HardCapMaxVel){ + playerStats.CurVel += playerStats.Acc * 10; + } + else if(playerStats.CurVel > playerStats.HardCapMaxVel){ + playerStats.CurVel = playerStats.HardCapMaxVel; + } + } + else{ + StartCoroutine(startCoolDown()); + isNitroing = false; + } } } private IEnumerator startCoolDown(){ Debug.Log("start corotine"); isOnCoolDown = true; - driver.startUICooldown("Nitro"); + //driver.startUICooldown("Nitro"); yield return new WaitForSeconds(nitroItem.cooldownM); isOnCoolDown = false; + tempTimer = 5; Debug.Log("end corotine"); } } diff --git a/Assets/Scripts/PlayerScripts/DebugPlayer/dPlayerMovement.cs b/Assets/Scripts/PlayerScripts/DebugPlayer/dPlayerMovement.cs index 7b24242..9c03141 100644 --- a/Assets/Scripts/PlayerScripts/DebugPlayer/dPlayerMovement.cs +++ b/Assets/Scripts/PlayerScripts/DebugPlayer/dPlayerMovement.cs @@ -94,6 +94,9 @@ public class dPlayerMovement : NetworkBehaviour //Grapple private dGrapplingHook grapple; + + //Nitro + private dNitro nitro; //Animation controller @@ -114,6 +117,7 @@ public class dPlayerMovement : NetworkBehaviour wallRun = GetComponent(); //Wallrun blink = GetComponent(); //Blink grapple = GetComponent(); + nitro = GetComponent(); //Get parents up direction up = GetComponentInParent().up; @@ -255,12 +259,15 @@ public class dPlayerMovement : NetworkBehaviour return pStats.CurVel; } //If the players speed is above or equal to max speed set speed to max - else if (pStats.CurVel >= pStats.MaxVel) + else if (pStats.CurVel >= pStats.MaxVel && nitro.isNitroing == false) { pStats.CurVel = pStats.MaxVel; return pStats.CurVel; } + else if(nitro.isNitroing){ + return pStats.CurVel; + } else{ Debug.Log("Something has gone wrong with the PlayerSpeed()"); return -1; diff --git a/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/Dash.cs b/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/Dash.cs index 70ea57f..e2738bf 100644 --- a/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/Dash.cs +++ b/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/Dash.cs @@ -31,7 +31,7 @@ public class Dash : NetworkBehaviour{ } void DashPlayer(){ - if (!IsLocalPlayer) { return; } + //if (!IsLocalPlayer) { return; } if(characterController.enabled == true){ if (Input.GetKeyDown(KeyCode.R) && isOnCoolDown == false) { @@ -54,7 +54,7 @@ public class Dash : NetworkBehaviour{ private IEnumerator startCoolDown(){ Debug.Log("start corotine"); isOnCoolDown = true; - //driver.startUICooldown("Nitro"); + //driver.startUICooldown(dashItem.name); yield return new WaitForSeconds(dashItem.cooldownM); isOnCoolDown = false; Debug.Log("end corotine"); diff --git a/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/GrapplingHook.cs b/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/GrapplingHook.cs index af01a2e..3a940b1 100644 --- a/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/GrapplingHook.cs +++ b/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/GrapplingHook.cs @@ -22,24 +22,32 @@ public class GrapplingHook : NetworkBehaviour float inclinationAngle; float theta = -1; - private float maxSwingSpeed = 90; - private float minSwingSpeed = 10; - private float swingSpeed = 0; + private float maxSwingSpeed = 50; + private float minSwingSpeed = 20; + private float swingAcc = 3f; + private float swingSpeed = 10; + + private float swingMom; + private float maxSwingMom = 60; - private float swingMom = 40; private Vector3 tensionMomDirection; private Vector3 hookPointRight; private Vector3 momDirection; + private Vector3 curXZDir; private Vector3 oldXZDir; - private float flip = -1; // flip variables for swing momentum + private bool swingback = false; //swing the player back - private float midpointMom; + private float oldSwingMom; Vector3 tensionDirection; float tensionForce; public Vector3 forceDirection; + private Vector3 tempRelease; + private Vector3 lerpRelease; + bool release = false; + // Start is called before the first frame update void Start() @@ -54,7 +62,7 @@ public class GrapplingHook : NetworkBehaviour // Update is called once per frame void Update() { - if (!IsLocalPlayer) { return; } + //if (!IsLocalPlayer) { return; } if ((Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton2)) && pStats.HasGrapple) //If grapple button is hit { @@ -64,23 +72,29 @@ public class GrapplingHook : NetworkBehaviour if (hookPointIndex != -1) //If there is a hookpoint { hookPoint = hookPoints[hookPointIndex]; //The point we are grappling from - ropeLength = Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) + 0.5f; + ropeLength = Vector3.Distance(gameObject.transform.position, hookPoint.transform.position); oldXZDir = (new Vector3(hookPoint.transform.position.x,0,hookPoint.transform.position.z) - new Vector3(transform.position.x,0,transform.position.z)).normalized; curXZDir = (new Vector3(hookPoint.transform.position.x,0,hookPoint.transform.position.z) - new Vector3(transform.position.x,0,transform.position.z)).normalized; + swingMom = CalculateSwingMom(playerMovement.driftVel.magnitude * 50f); + oldSwingMom = swingMom; + playerMovement.g = -1; isGrappled = true; //toggle grappling state + release = false; + lerpRelease = Vector3.zero; } } else //Else we are grappling { isGrappled = false; //toggle grappling state to release + release = true; + playerMovement.g = 0; } } } private void FixedUpdate() { - if (!IsLocalPlayer) { return; } - + //if (!IsLocalPlayer) { return; } if (isGrappled) { Debug.DrawRay(gameObject.transform.position, (hookPoint.transform.position - gameObject.transform.position)); //Visual of line @@ -111,31 +125,53 @@ public class GrapplingHook : NetworkBehaviour if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) >= ropeLength ) { - forceDirection = calculateForceDirection(1, playerMovement.g+.01f, hookPoint.transform.position); + forceDirection = CalculateForceDirection(1, playerMovement.g, hookPoint.transform.position) + RopeLengthOffset(hookPoint.transform.position, Vector3.Distance(gameObject.transform.position, hookPoint.transform.position)); + } + else{ + forceDirection = Vector3.zero; + } //apply special swing movement when aerial if(!playerMovement.isGrounded){ - movementController.Move(swingMoveController()); + movementController.Move(SwingMoveController()); if(swingMom != 0){ - movementController.Move(calculateMomentumDirection(playerMovement.g, hookPoint.transform.position)); + movementController.Move(CalculateMomentumDirection(playerMovement.g, hookPoint.transform.position)); swingMom -= .5f; } } + else{ + swingMom = CalculateSwingMom(playerMovement.driftVel.magnitude * 50f); + } + if(swingMom<0) swingMom = 0; + + tempRelease = CalculateSwingReleaseForce(); } - else if(!isGrappled || playerMovement.isGrounded){ - flip = -1; + else if(!isGrappled){ + //Reset force direction after unhook + forceDirection = Vector3.zero; swingback = true; - swingMom = 50; + + if(release){ + lerpRelease = Vector3.Lerp(lerpRelease, tempRelease, 10 * Time.deltaTime); + movementController.Move(lerpRelease); + } + + } + //WILL NEED ADJUSTMENT OR REMOVAL IN THE FUTURE //ungrapple on jump - if(playerMovement.GetJumpPressed()) isGrappled = false; - - //Reset force direction after unhook - if(isGrappled == false) forceDirection = Vector3.zero; + if(playerMovement.GetJumpPressed() && !playerMovement.isGrounded && isGrappled){ + release = true; + isGrappled = false; + } + if(playerMovement.isGrounded){ + swingback = true; + release = false; + } } //Finds the nearest hook to the player @@ -154,8 +190,17 @@ public class GrapplingHook : NetworkBehaviour return index; } + //Needs to be Overhauled to properly implement energy loss taking into account players current Velocity, height and input + //------Important Equations-------- + // TensionForce = Cos(theta) * g * m * Vector3(tensionDirection) + // Potential Energy = m * g * h -- Will need to modify adding current speed + // Kinetic Energy = 1/2 * m * V^2 -- assuming no energy loss at the bottom KE = PE at peak we will add energy loss ourselves + // Total Energy = m * ((g*h) + (1/2 * V^2)) + // Velocity = (2 * ((TotalEnergy/m) - (g*h)))^(1/2) -- This hypothetically could be used for our swing momentum calculation + // Movement Direction right angle of tension force = Sin(theta) * g * m * Vector3(Right angle to tensionDirection) + //Calculate the tether direction vector and how much force that vector needs - Vector3 calculateForceDirection(float mass, float g, Vector3 hPoint){ + Vector3 CalculateForceDirection(float mass, float g, Vector3 hPoint){ //tension direction and angle calculation tensionDirection = (hPoint - transform.position).normalized; @@ -171,33 +216,48 @@ public class GrapplingHook : NetworkBehaviour return fDirection; } - Vector3 calculateMomentumDirection(float g, Vector3 hPoint){ + Vector3 CalculateMomentumDirection(float g, Vector3 hPoint){ tensionMomDirection = (hPoint - transform.position).normalized; - hookPointRight = Vector3.Cross((new Vector3(hPoint.x,0,hPoint.z) - new Vector3(transform.position.x,0,transform.position.z)), transform.up).normalized; - momDirection = flip * Vector3.Cross(hookPointRight, tensionMomDirection).normalized; + hookPointRight = Vector3.Cross(oldXZDir, transform.up).normalized; + momDirection = -1 * Vector3.Cross(hookPointRight, tensionMomDirection).normalized; - if(oldXZDir != curXZDir && flip == -1){ - flip = 1; - midpointMom = swingMom; + if(oldXZDir != curXZDir){ + //midpointMom = swingMom; swingback = false; - Debug.Log("flip"); + //Debug.Log("flip"); } - if(swingback == false && swingMom <= (midpointMom*(.75f))){ + if(swingback == false && swingMom <= (oldSwingMom*(.75f))){ swingback = true; - flip = -1; + oldSwingMom = swingMom; oldXZDir = (new Vector3(hookPoint.transform.position.x,0,hookPoint.transform.position.z) - new Vector3(transform.position.x,0,transform.position.z)).normalized; - Debug.Log("swingback"); + //Debug.Log("swingback"); } curXZDir = (new Vector3(hPoint.x,0,hPoint.z) - new Vector3(transform.position.x,0,transform.position.z)).normalized; Debug.DrawRay(transform.position, momDirection * Time.deltaTime* 100, Color.green); return (momDirection * Time.deltaTime * swingMom); } + + //Calculates the players initial swing momentum using their height and their current velocity + float CalculateSwingMom(float playerSpeed){ + + //Calculate the players height compared to the lowest point in the swing + float swingHeight = transform.position.y - (hookPoint.transform.position.y - ropeLength); + if(swingHeight <= 1){ + swingHeight = 1; + } + + float sMom = playerSpeed + (swingHeight*2); + if(sMom > maxSwingMom){ + sMom = maxSwingMom; + } + return sMom; + } //Special movement for the player while they swing - Vector3 swingMoveController(){ + Vector3 SwingMoveController(){ //WASD input float inputVert = Input.GetAxis("Vertical"); @@ -207,14 +267,49 @@ public class GrapplingHook : NetworkBehaviour if((!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S))) inputVert = 0; if((!Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))) inputHor = 0; + //Swingspeed build up + if((inputVert != 0 || inputHor != 0) && swingSpeed < maxSwingSpeed){ + swingSpeed += swingAcc; + } + else if((inputVert != 0 || inputHor != 0) && swingSpeed >= maxSwingSpeed){ + swingSpeed = maxSwingSpeed; + } + else if((inputVert == 0 && inputHor == 0)){ + swingSpeed = minSwingSpeed; + } + //Swing direction based on player input swingDirection = Vector3.Cross(tensionDirection, ((transform.right * -inputVert) + (transform.forward * inputHor))).normalized; + //NEED TO ADD SWINGSPEED EASING + //this could be just adding a gradual increase in the swing speed instead of using a flat rate //Swing movement with swing speed added - Vector3 swingMovement = (swingDirection * Time.deltaTime * maxSwingSpeed); + Vector3 swingMovement = (swingDirection * Time.deltaTime * swingSpeed); return (swingMovement); } + + Vector3 RopeLengthOffset(Vector3 hPoint, float curDistance){ + + //How powerful our offset movement has to be + float offsetPower = ((curDistance - ropeLength) * 200f); + + //The direction we need to apply force to offset when the rope gets lengthened beyond the necessary point + Vector3 tenDirOffset = (hPoint - transform.position).normalized; + + + return tenDirOffset * offsetPower * Time.deltaTime; + } + + Vector3 CalculateSwingReleaseForce(){ + Vector3 releaseSwingForceDirection = momDirection * (swingMom + 20); + releaseSwingForceDirection = new Vector3(releaseSwingForceDirection.x,0,releaseSwingForceDirection.z); + + if(swingMom < 5){ + return Vector3.zero; + } + return releaseSwingForceDirection * Time.deltaTime; + } } diff --git a/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/Nitro.cs b/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/Nitro.cs index 0f28ab8..12760a8 100644 --- a/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/Nitro.cs +++ b/Assets/Scripts/PlayerScripts/PlayerItems/ItemScripts/Nitro.cs @@ -8,6 +8,9 @@ public class Nitro : MonoBehaviour private PlayerStats playerStats; public SpecialItem nitroItem; private bool isOnCoolDown = false; + public bool isNitroing = false; + + private float tempTimer = 5; //this will need to be set from scritable object or something; // Start is called before the first frame update @@ -23,16 +26,40 @@ public class Nitro : MonoBehaviour //once cooldowns are implemented, put this on one (a long one) if (Input.GetKeyDown(KeyCode.LeftShift) && isOnCoolDown == false && playerStats.HasNitro) { - playerStats.CurVel = playerStats.MaxVel; - StartCoroutine(startCoolDown()); + isNitroing = true; + + } + } + + void FixedUpdate(){ + if(isNitroing){ + if(tempTimer > 0){ + + tempTimer -= .01f; + + Debug.Log("nitro is on"); + + if(playerStats.CurVel < playerStats.HardCapMaxVel){ + playerStats.CurVel += playerStats.Acc * 10; + } + else if(playerStats.CurVel > playerStats.HardCapMaxVel){ + playerStats.CurVel = playerStats.HardCapMaxVel; + } + } + else{ + StartCoroutine(startCoolDown()); + isNitroing = false; + } } } private IEnumerator startCoolDown(){ Debug.Log("start corotine"); isOnCoolDown = true; - driver.startUICooldown("Nitro"); + //driver.startUICooldown("Nitro"); yield return new WaitForSeconds(nitroItem.cooldownM); isOnCoolDown = false; + tempTimer = 5; + Debug.Log("end corotine"); } } diff --git a/Assets/Scripts/PlayerScripts/PlayerMovement.cs b/Assets/Scripts/PlayerScripts/PlayerMovement.cs index 2aaf487..d2de145 100644 --- a/Assets/Scripts/PlayerScripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerScripts/PlayerMovement.cs @@ -94,6 +94,9 @@ public class PlayerMovement : NetworkBehaviour //Grapple private GrapplingHook grapple; + + //Nitro + private Nitro nitro; //Animation controller @@ -114,6 +117,7 @@ public class PlayerMovement : NetworkBehaviour wallRun = GetComponent(); //Wallrun blink = GetComponent(); //Blink grapple = GetComponent(); + nitro = GetComponent(); //Get parents up direction up = GetComponentInParent().up; @@ -220,6 +224,7 @@ public class PlayerMovement : NetworkBehaviour } //Move Player if(grapple.isGrappled && !isGrounded){ + driftVel = Vector3.zero; moveController.Move(((moveY + grapple.forceDirection) * Time.deltaTime)); } else{ @@ -236,7 +241,7 @@ public class PlayerMovement : NetworkBehaviour { WallCheck(); //If nothing is pressed speed is 0 - if ((Input.GetAxis("Vertical") == 0.0f && Input.GetAxis("Horizontal") == 0.0f) || isSliding ||(grapple.isGrappled && !isGrounded)) + if ((Input.GetAxis("Vertical") == 0.0f && Input.GetAxis("Horizontal") == 0.0f) || isSliding || (grapple.isGrappled && !isGrounded)) { pStats.CurVel = 0.0f; return pStats.CurVel; @@ -254,10 +259,18 @@ public class PlayerMovement : NetworkBehaviour return pStats.CurVel; } //If the players speed is above or equal to max speed set speed to max - else + else if (pStats.CurVel >= pStats.MaxVel && nitro.isNitroing == false) { pStats.CurVel = pStats.MaxVel; return pStats.CurVel; + + } + else if(nitro.isNitroing){ + return pStats.CurVel; + } + else{ + Debug.Log("Something has gone wrong with the PlayerSpeed()"); + return -1; } } @@ -288,6 +301,7 @@ public class PlayerMovement : NetworkBehaviour if(wallRun.IsWallRunning()){ AddImpact((wallRun.GetWallJumpDirection()), pStats.JumpPow * 8.5f); g = pStats.JumpPow; + curJumpNum = 0; } else{ @@ -390,6 +404,7 @@ public class PlayerMovement : NetworkBehaviour } + //REMOVE WHEN UNNECCESARY //Respawns player if they fall below a certain point private void Respawn()