public override void HandleInput() { //first, let's check to see if any ledge that we are //If the player is moving on the horizontal axis, not accidentally Vector2 fixedMI = HelperFunctions.ConvertMoveInputToCam(mi, pi.playerScript.GetCurrentCamera().transform); if (Mathf.Abs(fixedMI.x) >= 0.2f || Mathf.Abs(fixedMI.y) >= 0.2f) { pi.GetRigidbody().constraints = pi.GetFreezeAllRotation(); pi.currentState = new PlayerStateClimbing(pi, ledge); } if (cancelClimb > 0) { //drop the player and make it so that they won't accidentally grab the same ledge pi.playerScript.SetCanClimb(false); pi.GetRigidbody().constraints = pi.GetFreezeAllRotation(); pi.gameObject.GetComponent <Rigidbody>().useGravity = true; //Disable the ledge so you dont instantly attach to it again ledge.GetComponent <LedgeScript>().DisableColliderTemporarily(); pi.currentState = new PlayerStateFalling(pi); } if (jumpInput > 0f && canJump) { //drop the player and make it so that they won't accidentally grab the same ledge pi.playerScript.SetCanClimb(false); pi.GetRigidbody().constraints = pi.GetFreezeAllRotation(); pi.gameObject.GetComponent <Rigidbody>().useGravity = true; //Disable the ledge so you dont instantly attach to it again ledge.GetComponent <LedgeScript>().DisableColliderTemporarily(); pi.currentState = new PlayerStateJumping(pi); } }
public PlayerStateHangingOnLedge(PlayerInputScript player, GameObject go) { pi = player; ledge = go; //Ensure that the player is rotated facing the ledge Quaternion r = ledge.GetComponent <LedgeScript>().GetRotation(); Transform t = pi.playerScript.GetPlayerTransform(); t.eulerAngles = new Vector3(t.eulerAngles.x, r.eulerAngles.y - 90, t.eulerAngles.z); //Turn off gravity so that the player doesn't fall pi.gameObject.GetComponent <Rigidbody>().useGravity = false; Debug.Log("Hanging on ledge state"); //Freeze the player so that they don't rotate or move while hanging on the ledge pi.GetRigidbody().constraints = pi.GetFreezeAll(); //Player cannot jump until they stop pressing the jump input canJump = false; }