mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-07-01 00:40:23 -05:00
Updated the non debug files
This commit is contained in:
parent
2da2237835
commit
fca69d01d0
|
|
@ -24,6 +24,7 @@ public class KickController : NetworkBehaviour
|
|||
}
|
||||
|
||||
void Update(){
|
||||
if (!IsLocalPlayer) { return; }
|
||||
Kick();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ using System.Collections.Generic;
|
|||
using MLAPI;
|
||||
using UnityEngine;
|
||||
|
||||
public class GrapplingHook : NetworkBehaviour
|
||||
public class dGrapplingHook : NetworkBehaviour
|
||||
{
|
||||
public float maxGrappleDistance = 25;
|
||||
public float maxGrappleDistance = 15;
|
||||
|
||||
public bool isGrappled;
|
||||
private int hookPointIndex;
|
||||
|
|
@ -18,10 +18,25 @@ public class GrapplingHook : NetworkBehaviour
|
|||
private PlayerStats pStats;
|
||||
[SerializeField] private float ropeLength;
|
||||
private float climbRate = 5;
|
||||
private Vector3 swingDirection;
|
||||
float inclinationAngle;
|
||||
float theta = -1;
|
||||
|
||||
private float maxSwingSpeed = 90;
|
||||
private float minSwingSpeed = 10;
|
||||
private float swingSpeed = 0;
|
||||
|
||||
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;
|
||||
|
||||
Vector3 tensionDirection;
|
||||
Vector3 pendulumSideDirection;
|
||||
Vector3 tangentDirection;
|
||||
float tensionForce;
|
||||
public Vector3 forceDirection;
|
||||
|
||||
|
|
@ -32,7 +47,7 @@ public class GrapplingHook : NetworkBehaviour
|
|||
isGrappled = false;
|
||||
hookPoints = GameObject.FindGameObjectsWithTag("HookPoint");
|
||||
movementController = gameObject.GetComponent<CharacterController>();
|
||||
playerMovement = gameObject.GetComponent<PlayerMovement>();
|
||||
playerMovement = gameObject.GetComponent<dPlayerMovement>();
|
||||
pStats = gameObject.GetComponent<PlayerStats>();
|
||||
}
|
||||
|
||||
|
|
@ -50,12 +65,13 @@ public class GrapplingHook : NetworkBehaviour
|
|||
{
|
||||
hookPoint = hookPoints[hookPointIndex]; //The point we are grappling from
|
||||
ropeLength = Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) + 0.5f;
|
||||
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;
|
||||
isGrappled = true; //toggle grappling state
|
||||
}
|
||||
}
|
||||
else //Else we are grappling
|
||||
{
|
||||
//physics tear down?
|
||||
isGrappled = false; //toggle grappling state to release
|
||||
}
|
||||
}
|
||||
|
|
@ -68,7 +84,8 @@ public class GrapplingHook : NetworkBehaviour
|
|||
{
|
||||
Debug.DrawRay(gameObject.transform.position, (hookPoint.transform.position - gameObject.transform.position)); //Visual of line
|
||||
|
||||
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.JoystickButton4)) //Extend hook
|
||||
//Extend Hook
|
||||
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.JoystickButton4))
|
||||
{
|
||||
ropeLength += climbRate * Time.deltaTime;
|
||||
if (ropeLength > maxGrappleDistance)
|
||||
|
|
@ -77,7 +94,9 @@ public class GrapplingHook : NetworkBehaviour
|
|||
}
|
||||
//Debug.Log(ropeLength.ToString());
|
||||
}
|
||||
if (Input.GetKey(KeyCode.RightShift) || Input.GetKey(KeyCode.JoystickButton5)) // Retract Hook
|
||||
|
||||
//Retract Hook
|
||||
if (Input.GetKey(KeyCode.RightShift) || Input.GetKey(KeyCode.JoystickButton5))
|
||||
{
|
||||
ropeLength -= climbRate * Time.deltaTime;
|
||||
if (ropeLength < 5)
|
||||
|
|
@ -86,17 +105,40 @@ public class GrapplingHook : NetworkBehaviour
|
|||
}
|
||||
//Debug.Log(ropeLength.ToString());
|
||||
}
|
||||
//Do grappling physics based on hookPoint
|
||||
if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) > ropeLength )
|
||||
//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 )
|
||||
{
|
||||
//Impact Based
|
||||
forceDirection = calculateForceDirection(1, playerMovement.g, hookPoint.transform.position);
|
||||
|
||||
forceDirection = calculateForceDirection(1, playerMovement.g+.01f, hookPoint.transform.position);
|
||||
|
||||
}
|
||||
|
||||
//apply special swing movement when aerial
|
||||
if(!playerMovement.isGrounded){
|
||||
movementController.Move(swingMoveController());
|
||||
if(swingMom != 0){
|
||||
movementController.Move(calculateMomentumDirection(playerMovement.g, hookPoint.transform.position));
|
||||
swingMom -= .5f;
|
||||
}
|
||||
}
|
||||
if(swingMom<0) swingMom = 0;
|
||||
}
|
||||
else if(!isGrappled || playerMovement.isGrounded){
|
||||
flip = -1;
|
||||
swingback = true;
|
||||
swingMom = 50;
|
||||
}
|
||||
//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;
|
||||
}
|
||||
|
||||
//Finds the nearest hook to the player
|
||||
int FindHookPoint()
|
||||
{
|
||||
float least = maxGrappleDistance;
|
||||
|
|
@ -112,19 +154,66 @@ public class GrapplingHook : NetworkBehaviour
|
|||
return index;
|
||||
}
|
||||
|
||||
//Calculate the tether direction vector and how much force that vector needs
|
||||
Vector3 calculateForceDirection(float mass, float g, Vector3 hPoint){
|
||||
|
||||
//tension direction and angle calculation
|
||||
tensionDirection = (hPoint - transform.position).normalized;
|
||||
Debug.Log(tensionDirection);
|
||||
inclinationAngle = Vector3.Angle((transform.position - hPoint).normalized, -transform.up);
|
||||
theta = Mathf.Deg2Rad * inclinationAngle;
|
||||
if(theta<=.1) theta = 0;
|
||||
|
||||
float inclinationAngle = Vector3.Angle(transform.position - hPoint, -transform.up);
|
||||
|
||||
|
||||
tensionForce = mass * -g * Mathf.Cos(Mathf.Deg2Rad * inclinationAngle);
|
||||
Debug.Log(g);
|
||||
//How much force the tension needs
|
||||
tensionForce = mass * -g * Mathf.Cos(theta);
|
||||
|
||||
//force direction calculation based on tension direction and force
|
||||
Vector3 fDirection = tensionDirection * tensionForce;
|
||||
Debug.Log(fDirection);
|
||||
return fDirection;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if(oldXZDir != curXZDir && flip == -1){
|
||||
flip = 1;
|
||||
midpointMom = swingMom;
|
||||
swingback = false;
|
||||
Debug.Log("flip");
|
||||
}
|
||||
|
||||
if(swingback == false && swingMom <= (midpointMom*(.75f))){
|
||||
swingback = true;
|
||||
flip = -1;
|
||||
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);
|
||||
return (momDirection * Time.deltaTime * swingMom);
|
||||
}
|
||||
|
||||
//Special movement for the player while they swing
|
||||
Vector3 swingMoveController(){
|
||||
|
||||
//WASD input
|
||||
float inputVert = Input.GetAxis("Vertical");
|
||||
float inputHor = Input.GetAxis("Horizontal");
|
||||
|
||||
//input is zero when nothing is pressed to prevent button easing values
|
||||
if((!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S))) inputVert = 0;
|
||||
if((!Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))) inputHor = 0;
|
||||
|
||||
//Swing direction based on player input
|
||||
swingDirection = Vector3.Cross(tensionDirection, ((transform.right * -inputVert) + (transform.forward * inputHor))).normalized;
|
||||
|
||||
//NEED TO ADD SWINGSPEED EASING
|
||||
//Swing movement with swing speed added
|
||||
Vector3 swingMovement = (swingDirection * Time.deltaTime * maxSwingSpeed);
|
||||
|
||||
|
||||
return (swingMovement);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using UnityEngine.Rendering;
|
|||
public class WallRun : NetworkBehaviour
|
||||
{
|
||||
|
||||
public float wallMaxDistance = 3;
|
||||
public float wallMaxDistance = 3f;
|
||||
public float wallSpeedMultiplier = 1.2f;
|
||||
public float minimumHeight = .1f;
|
||||
public float maxAngleRoll = 20;
|
||||
|
|
@ -170,7 +170,7 @@ public class WallRun : NetworkBehaviour
|
|||
}
|
||||
|
||||
moveToSet.y = 0;
|
||||
|
||||
//
|
||||
|
||||
playerMovementController.SetPlayerVelocity(moveToSet);
|
||||
isWallRunning = true;
|
||||
|
|
@ -196,5 +196,5 @@ public class WallRun : NetworkBehaviour
|
|||
public Vector3 GetWallJumpDirection() //Add call in jump where if we are wallrunning and jump, the jump vector is multiplied by this
|
||||
{
|
||||
return lastWallNormal * wallBouncing + (transform.up);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,10 @@ public class PlayerMovement : 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 PlayerMovement : NetworkBehaviour
|
|||
//Blink
|
||||
private Blink blink;
|
||||
|
||||
//Grapple
|
||||
private GrapplingHook grapple;
|
||||
|
||||
|
||||
|
|
@ -215,8 +219,14 @@ public class PlayerMovement : NetworkBehaviour
|
|||
if(animator != null) animator.SetBool("isRunning", false);
|
||||
}
|
||||
//Move Player
|
||||
moveController.Move(driftVel + (moveY * Time.deltaTime));
|
||||
if(grapple.isGrappled) moveController.Move(grapple.forceDirection * Time.deltaTime);
|
||||
if(grapple.isGrappled && !isGrounded){
|
||||
moveController.Move(((moveY + grapple.forceDirection) * Time.deltaTime));
|
||||
}
|
||||
else{
|
||||
moveController.Move(driftVel + (moveY * Time.deltaTime));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -226,7 +236,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)
|
||||
if ((Input.GetAxis("Vertical") == 0.0f && Input.GetAxis("Horizontal") == 0.0f) || isSliding ||(grapple.isGrappled && !isGrounded))
|
||||
{
|
||||
pStats.CurVel = 0.0f;
|
||||
return pStats.CurVel;
|
||||
|
|
@ -458,6 +468,11 @@ public class PlayerMovement : NetworkBehaviour
|
|||
else{
|
||||
g = 0;
|
||||
}
|
||||
|
||||
//Caps out the players downwards speed
|
||||
if(g < maxG){
|
||||
g = maxG;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user