public static bool CheckLedgeGrab(Collision collision) { foreach (ContactPoint contact in collision) { Collider ledgeGrab = null; CSceneObject sceneLedge = null; if (contact.otherCollider != null && contact.otherCollider.gameObject.name == "Ledge_Grab_Detection") { ledgeGrab = contact.otherCollider; if (contact.thisCollider != null && contact.thisCollider.gameObject != null) { sceneLedge = contact.thisCollider.gameObject.GetComponent <CSceneObject>(); } } else if (contact.thisCollider != null && contact.thisCollider.gameObject.name == "Ledge_Grab_Detection") { ledgeGrab = contact.thisCollider; if (contact.otherCollider != null && contact.otherCollider.gameObject != null) { sceneLedge = contact.otherCollider.gameObject.GetComponent <CSceneObject>(); } } if (sceneLedge == null || !sceneLedge.CanLedgeGrab) { if (ledgeGrab != null) { ledgeGrab.enabled = false; } continue; } if (ledgeGrab != null) { if (CPlayerPhysics.isNearly(contact.normal.normalized.y, -1.0f, 0.1f)) { // player hit the ledge grab area GameObject player = contact.otherCollider.gameObject.transform.parent.gameObject; if (player != null) { CEntityPlayer playerEntity = player.GetComponent <CEntityPlayer>(); if (playerEntity != null && playerEntity.GetPlayerState() != PlayerState.LedgeHang && playerEntity.GetPlayerState() != PlayerState.LedgeClimb && playerEntity.GetPlayerState() != PlayerState.LedgeClimbComplete ) { CPlayerPhysics phy = playerEntity.Physics; phy.SetLedgeGrabState(playerEntity, PlayerState.LedgeHang); contact.otherCollider.enabled = false; return(true); } } } else { ledgeGrab.enabled = false; return(false); } } } return(false); }