mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-22 10:24:42 -05:00
idle grapple calculations have been solidified
I can now move into adding how player speed and height effect these things
This commit is contained in:
@@ -26,7 +26,7 @@ public class dGrapplingHook : NetworkBehaviour
|
||||
private float minSwingSpeed = 10;
|
||||
private float swingSpeed = 0;
|
||||
|
||||
private float swingMom = 40;
|
||||
private float swingMom = 50;
|
||||
private Vector3 tensionMomDirection;
|
||||
private Vector3 hookPointRight;
|
||||
private Vector3 momDirection;
|
||||
@@ -34,7 +34,7 @@ public class dGrapplingHook : NetworkBehaviour
|
||||
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;
|
||||
@@ -67,6 +67,7 @@ public class dGrapplingHook : NetworkBehaviour
|
||||
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;
|
||||
oldSwingMom = swingMom;
|
||||
isGrappled = true; //toggle grappling state
|
||||
}
|
||||
}
|
||||
@@ -176,27 +177,36 @@ 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){
|
||||
|
||||
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 + new Vector3(.0001f,.0001f,.0001f);
|
||||
|
||||
if(oldXZDir != curXZDir && flip == -1){
|
||||
flip = 1;
|
||||
midpointMom = swingMom;
|
||||
//midpointMom = swingMom;
|
||||
swingback = false;
|
||||
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");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
id: 11
|
||||
itemName: Dash
|
||||
description: Quickly Moves the player forwards
|
||||
description: Press F to quickly dash your player forward.
|
||||
itemSprite: {fileID: 0}
|
||||
maxVelM: 0
|
||||
minVelM: 0
|
||||
curVelM: 0
|
||||
|
||||
@@ -14,7 +14,7 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
id: 7
|
||||
itemName: Glider
|
||||
description: Player Will Fall slower
|
||||
description: Hold space while falling to slow your descent.
|
||||
itemSprite: {fileID: 7798176430303134427, guid: 7f448051c9c906545bfd88ed2754392b, type: 3}
|
||||
maxVelM: 0
|
||||
minVelM: 0
|
||||
|
||||
@@ -14,7 +14,7 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
id: 8
|
||||
itemName: Grapple
|
||||
description: Allows the use of a grapple
|
||||
description: Press E to grapple to a nearby grapple point.
|
||||
itemSprite: {fileID: -7389470788071104723, guid: 7f448051c9c906545bfd88ed2754392b, type: 3}
|
||||
maxVelM: 0
|
||||
minVelM: 0
|
||||
|
||||
@@ -14,7 +14,8 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
id: 10
|
||||
itemName: Nitro
|
||||
description: Boosts player speed
|
||||
description: Press Left Shift to boost your player speed beyond its max for a short
|
||||
period.
|
||||
itemSprite: {fileID: -295526885773654649, guid: 7f448051c9c906545bfd88ed2754392b, type: 3}
|
||||
maxVelM: 0
|
||||
minVelM: 0
|
||||
|
||||
@@ -14,7 +14,7 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
id: 2
|
||||
itemName: Roller Skates
|
||||
description: More Slidey But Faster
|
||||
description: Increases your max speed and acceleration at the cost of traction.
|
||||
itemSprite: {fileID: -3696225328785611619, guid: 7f448051c9c906545bfd88ed2754392b, type: 3}
|
||||
maxVelM: 15
|
||||
minVelM: 0
|
||||
|
||||
@@ -14,7 +14,7 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
id: 3
|
||||
itemName: Springs
|
||||
description: Jump Higher
|
||||
description: Your jumps will be more powerful.
|
||||
itemSprite: {fileID: 3996138432854981312, guid: 7f448051c9c906545bfd88ed2754392b, type: 3}
|
||||
maxVelM: 0
|
||||
minVelM: 0
|
||||
|
||||
@@ -14,7 +14,8 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
id: 4
|
||||
itemName: Strong Kick
|
||||
description: Kick Harder
|
||||
description: Your kick will become more powerful.
|
||||
itemSprite: {fileID: 0}
|
||||
maxVelM: 0
|
||||
minVelM: 0
|
||||
curVelM: 0
|
||||
|
||||
@@ -14,7 +14,8 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
id: 5
|
||||
itemName: Triple Jump
|
||||
description: Player gets an extra jump but has less jump height
|
||||
description: Your jump height will be reduced slightly but you will gain an extra
|
||||
jump.
|
||||
itemSprite: {fileID: -8809284872407378732, guid: 7f448051c9c906545bfd88ed2754392b, type: 3}
|
||||
maxVelM: 0
|
||||
minVelM: 0
|
||||
|
||||
@@ -14,7 +14,7 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
id: 6
|
||||
itemName: Wall Run
|
||||
description: Allows player to run on walls
|
||||
description: You now have the ability to run across red walls.
|
||||
itemSprite: {fileID: -7634698977955767800, guid: 7f448051c9c906545bfd88ed2754392b, type: 3}
|
||||
maxVelM: 0
|
||||
minVelM: 0
|
||||
|
||||
Reference in New Issue
Block a user