Merge branch 'GrapplingHook'

This commit is contained in:
Vincent Wheat
2021-11-01 13:20:19 -05:00
38 changed files with 36247 additions and 14 deletions

View File

@@ -12,11 +12,20 @@ public class GrapplingHook : MonoBehaviour
private GameObject[] hookPoints;
private float distance;
private CharacterController movementController;
private PlayerMovement playerMovement;
private PlayerStats pStats;
private float ropeLength;
private float climbRate = 5;
// Start is called before the first frame update
void Start()
{
isGrappled = false;
hookPoints = GameObject.FindGameObjectsWithTag("HookPoint");
movementController = gameObject.GetComponent<CharacterController>();
playerMovement = gameObject.GetComponent<PlayerMovement>();
pStats = gameObject.GetComponent<PlayerStats>();
}
// Update is called once per frame
@@ -30,7 +39,7 @@ public class GrapplingHook : MonoBehaviour
if (hookPointIndex != -1) //If there is a hookpoint
{
hookPoint = hookPoints[hookPointIndex]; //The point we are grappling from
//physics set up?
ropeLength = Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) + 0.5f;
isGrappled = true; //toggle grappling state
}
}
@@ -46,7 +55,35 @@ public class GrapplingHook : MonoBehaviour
{
if (isGrappled)
{
Debug.DrawRay(gameObject.transform.position, (hookPoint.transform.position - gameObject.transform.position)); //Visual of line
if (Input.GetKey(KeyCode.LeftShift)) //Extend hook
{
ropeLength += climbRate * Time.deltaTime;
if (ropeLength > maxGrappleDistance)
{
ropeLength = maxGrappleDistance;
}
//Debug.Log(ropeLength.ToString());
}
if (Input.GetKey(KeyCode.RightShift)) // Retract Hook
{
ropeLength -= climbRate * Time.deltaTime;
if (ropeLength < 5)
{
ropeLength = 5;
}
//Debug.Log(ropeLength.ToString());
}
//Do grappling physics based on hookPoint
if (Vector3.Distance(gameObject.transform.position, hookPoint.transform.position) > ropeLength)
{
//Impact Based
playerMovement.AddImpact((hookPoint.transform.position - gameObject.transform.position), pStats.PlayerGrav);
//Character controller move?
//movementController.Move((hookPoint.transform.position - gameObject.transform.position).normalized * ropeLength*Time.deltaTime);
//Lerp? or another smoother way? Better physics? Wait until refinement to deal with
}
}
}

View File

@@ -32,6 +32,7 @@ public class WallRun : MonoBehaviour
float elapsedTimeSinceWallAttach = 0;
float elapsedTimeSinceWallDetatch = 0;
bool jumping;
private bool regainedJump = false;
bool isPlayergrounded() => playerMovementController.isGrounded;
@@ -111,11 +112,17 @@ public class WallRun : MonoBehaviour
elapsedTimeSinceWallDetatch = 0;
elapsedTimeSinceWallAttach += Time.deltaTime;
playerMovementController.AddPlayerVelocity((Vector3.down * wallGravityDownForce * Time.deltaTime));
if (elapsedTimeSinceWallAttach > 0.125f && regainedJump == false)//Allows players to always jump off of walls
{
regainedJump = true;
playerMovementController.decrementCurrentJumpNumber();
}
}
else
{
elapsedTimeSinceWallAttach = 0;
elapsedTimeSinceWallDetatch += Time.deltaTime;
regainedJump = false;
}
}
@@ -147,8 +154,9 @@ public class WallRun : MonoBehaviour
Vector3 moveToSet = alongWall * vertical * playerMovementController.PlayerSpeed() *Time.deltaTime;// * wallSpeedMultiplier;
moveToSet.y = 0;
Vector3 cancelDrop = new Vector3(0, 0.01f, 0);
playerMovementController.SetPlayerVelocity(moveToSet);
playerMovementController.AddPlayerVelocity(cancelDrop);
//Debug.Log("On Wall");
isWallRunning = true;
}

View File

@@ -95,7 +95,6 @@ public class PlayerMovement : NetworkBehaviour
capCol.enabled = false;
//Wallrun
wallRun = gameObject.GetComponent<WallRun>();
up = this.gameObject.GetComponentInParent<Transform>().up;
}
@@ -151,6 +150,8 @@ public class PlayerMovement : NetworkBehaviour
}
//TESTING RAGDOLL STUFF NEEDS SOME WORK
//Checks if player should respawn
//Respawn();
if (Input.GetMouseButton(1) && heldDown == false){
getHit(new Vector3(vel.x, 0, vel.z), 30);
@@ -288,6 +289,12 @@ public class PlayerMovement : NetworkBehaviour
//Camera and Player Rotation
public void decrementCurrentJumpNumber()
{
curJumpNum--;
}
//Camera
private void Rotation()
{
Vector3 lastCamPos = new Vector3(0,0,0);