mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-08-21 09:54:28 -05:00
Made some small improvements to wallrun and the player prefabs
Grapple movement is a lot better just need to implement momentum
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ public class dWallRun : NetworkBehaviour
|
||||
}
|
||||
|
||||
moveToSet.y = 0;
|
||||
|
||||
//
|
||||
|
||||
playerMovementController.SetPlayerVelocity(moveToSet);
|
||||
isWallRunning = true;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user