void ButtonInputs() { // ---------- MENU CONTROLS ---------- if (Input.GetKeyDown(KeyCode.Escape)) { Cursor.lockState = CursorLockMode.None; UnityEditor.EditorApplication.ExitPlaymode(); // Application.Quit(); } if (Input.GetKeyDown(KeyCode.R)) { SceneManager.LoadScene(SceneManager.GetActiveScene().name); } // ---------- FREECAM CONTROLS ---------- if (Input.GetKeyDown(KeyCode.LeftAlt)) { playerCommons.modifyCamControl(true); } if (Input.GetKeyUp(KeyCode.LeftAlt)) { playerCommons.modifyCamControl(false); } }
void ButtonInputs() { if (Input.GetButton("Jump")) // The instance the button is active : Returns true whenever its pressed/held or active { playerStates.isOffGrounding = true; } else if (playerStates.isJumping || playerStates.isLedgeHopping) // If you let go of jump button while jumping { playerStates.isJumping = false; playerStates.isLedgeHopping = false; } if (Input.GetButtonDown("Jump")) // The instance the button is pressed : Returns true only once when pressed { if (playerStates.allowFreeMov) // If in free movement, not on locked movement { if (playerStates.isWallHoppable && !playerStates.isJumping) // #1 - Wall hop if wall hoppable and not mid jump { WallHop(); } else if (playerStates.isGrounded) // #2 - Regular jump if grounded { playerStates.isJumping = true; } else // #3 - Air dash if mid air { AirDash(); } } else // If in locked movement (wallrun, wallclimb, etc.) { if (playerStates.isWallRunning || playerStates.isWallClimbing) { playerCommons.updateWallInteractions(false, false, null); WallHop(); } else if (playerStates.isLedgeHanging) { float playerAngle = fpvCam.transform.rotation.eulerAngles.y; float angleRange = 15.0f; float angleMax = miscHelper.normalizeDegrees(playerStates.wallAngleY + angleRange); float angleMin = miscHelper.normalizeDegrees(playerStates.wallAngleY - angleRange); bool facingAngle = miscHelper.AngleRangeCheck(angleMin, angleMax, playerAngle); if (facingAngle) // TODO++ : REWORK LEDGEHOP TO AUTOMATICALLY TRIGGER ONCE THE PLAYER HAS BEGUN LEDGE HANGING { playerStates.isLedgeHopping = true; } else { WallHop(); } rb.useGravity = true; playerCommons.updateWallInteractions(null, null, false); } playerCommons.modifyControls(true, true); playerCommons.modifyCamControl(false); } } }
void WallContactCheck(Collision col) { ContactPoint firstContactPoint; if (col.contacts.Length > 0) { firstContactPoint = col.GetContact(0); } else { playerStates.isWallClimbable = false; playerStates.isWallRunnable = false; playerStates.isWallHoppable = false; return; } if (playerStates.isByWall && firstContactPoint.normal.y <= playerStates.wallNormalLimit) { float xComp = firstContactPoint.normal.x; float zComp = firstContactPoint.normal.z; float yRotationComp; // Angle of contact from the perspective of object you've collided with (other), looking left through right if (xComp == 0) { yRotationComp = Mathf.Acos(zComp); } else if (zComp == 0) { yRotationComp = Mathf.Asin(xComp); } else { yRotationComp = Mathf.Atan2(zComp, xComp); } float angleReference = (yRotationComp + Mathf.PI) * Mathf.Rad2Deg; // Radian angle required to face object (looking against direction of other) using angleofcontact as reference // Debug.Log(angleReference); if (!(firstContactPoint.otherCollider is BoxCollider && col.transform.rotation.eulerAngles.y == 0f)) { angleReference -= ((angleReference - 45f) / 45f) * 90f; // Adjustment if otherCollider is rotated (objects behave as if they were rotated 90 degrees when rotated at all) } // Debug.Log(miscHelper.normalizeDegrees(angleReference)); if (!playerStates.isGrounded && (!playerStates.isWallInteracting || playerStates.isWallClimbing)) { playerStates.isWallClimbable = WallClimbCheck(angleReference); } if (!playerStates.isGrounded && (!playerStates.isWallInteracting || playerStates.isWallRunning)) { playerStates.isWallRunnable = WallRunCheck(angleReference); } playerStates.isWallHoppable = WallHopCheck(angleReference); // Automatically triggers ability upon collision if (!playerStates.isLedgeHopping && !playerStates.isGrounded && WallHangCheck(angleReference, col)) // no angle checked because it can happen even when other checks have passed { Debug.Log("LedgeHanging"); playerCommons.resetPlayerInputs(true, false); playerCommons.modifyControls(false, true); playerCommons.modifyCamControl(true); rb.useGravity = false; rb.velocity = Vector3.zero; playerCommons.updateWallInteractions(null, null, true); } else if (playerStates.isLedgeHanging) // TODO++: REQUIRES MORE THINKING AS TO HOW THIS WILL AFFECT THE GAME { playerCommons.updateWallInteractions(null, null, false); rb.useGravity = true; playerCommons.modifyControls(true, true); playerCommons.modifyCamControl(false); } } }