diff --git a/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs b/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs index 0941a05..1398013 100644 --- a/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs +++ b/Assets/Scripts/PlayerScripts/DebugPlayer/DebugItems/dGrapplingHook.cs @@ -24,7 +24,8 @@ public class dGrapplingHook : NetworkBehaviour private float maxSwingSpeed = 90; private float minSwingSpeed = 10; - private float swingSpeed = 0; + private float swingAcc = 5f; + private float swingSpeed = 10; private float swingMom = 50; private Vector3 tensionMomDirection; @@ -110,10 +111,10 @@ public class dGrapplingHook : NetworkBehaviour //Debug.Log(Vector3.Distance(gameObject.transform.position, hookPoint.transform.position)); Debug.Log(ropeLength); //Calculate tether force direction based on hookpoint - if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) > ropeLength ) + if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) >= ropeLength ) { - forceDirection = calculateForceDirection(1, playerMovement.g+.01f, hookPoint.transform.position) + ropeLengthOffset(hookPoint.transform.position, Vector3.Distance(gameObject.transform.position, hookPoint.transform.position)); + forceDirection = CalculateForceDirection(1, playerMovement.g, hookPoint.transform.position) + RopeLengthOffset(hookPoint.transform.position, Vector3.Distance(gameObject.transform.position, hookPoint.transform.position)); } @@ -123,9 +124,9 @@ public class dGrapplingHook : NetworkBehaviour //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; } } @@ -138,7 +139,7 @@ public class dGrapplingHook : NetworkBehaviour } //WILL NEED ADJUSTMENT OR REMOVAL IN THE FUTURE //ungrapple on jump - if(playerMovement.GetJumpPressed()) isGrappled = false; + if(playerMovement.GetJumpPressed() && !playerMovement.isGrounded) isGrappled = false; //Reset force direction after unhook if(isGrappled == false) forceDirection = Vector3.zero; @@ -160,8 +161,17 @@ public class dGrapplingHook : 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; @@ -177,19 +187,11 @@ public class dGrapplingHook : NetworkBehaviour return fDirection; } - //Needs to be Overhauled to properly implement energy loss and work more consistently 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) - Vector3 calculateMomentumDirection(float g, Vector3 hPoint){ + Vector3 CalculateMomentumDirection(float g, Vector3 hPoint){ tensionMomDirection = (hPoint - transform.position).normalized; hookPointRight = Vector3.Cross(oldXZDir, transform.up).normalized; - momDirection = -1 * Vector3.Cross(hookPointRight, tensionMomDirection).normalized + new Vector3(.0001f,.0001f,.0001f); + momDirection = -1 * Vector3.Cross(hookPointRight, tensionMomDirection).normalized; if(oldXZDir != curXZDir && flip == -1){ //midpointMom = swingMom; @@ -206,12 +208,16 @@ public class dGrapplingHook : NetworkBehaviour 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); - Debug.Log((momDirection * swingMom).normalized); return (momDirection * Time.deltaTime * swingMom); } + + //Calculates the players initial swing momentum using their height and their current velocity + float CalculateSwingMom(Vector3 playerSpeed){ + return 0.0f; + } //Special movement for the player while they swing - Vector3 swingMoveController(){ + Vector3 SwingMoveController(){ //WASD input float inputVert = Input.GetAxis("Vertical"); @@ -221,27 +227,39 @@ public class dGrapplingHook : 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){ + Vector3 RopeLengthOffset(Vector3 hPoint, float curDistance){ //How powerful our offset movement has to be - float offsetPower = ((curDistance - ropeLength) * 10f); + 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; + return tenDirOffset * offsetPower * Time.deltaTime; } }