mirror of
https://github.com/Leahnaya/TheKingsRace.git
synced 2026-09-07 09:55:24 -05:00
Merge branch 'GrapplingHook'
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user