protected virtual void OnTriggerEnter(Collider other) { JCS_2DSideScrollerPlayer player = other.GetComponent <JCS_2DSideScrollerPlayer>(); if (player == null) { return; } AddSafe(player); bool isTopOfBox = JCS_Physics.TopOfBox( player.GetCharacterController(), mPositionPlatform.GetPlatformCollider()); if (isTopOfBox) { // show character behind the ladder int backOrderLayer = OrderLayerObject.sortingOrder - ClimbableManager.SORTING_ORDER_BEHIND_OFFSET; SetPlayerSortingOrder(player, backOrderLayer); } else { // show character infront int frontOrderLayer = OrderLayerObject.sortingOrder + ClimbableManager.SORTING_ORDER_INFRONT_OFFSET; SetPlayerSortingOrder(player, frontOrderLayer); } player.CanLadder = true; player.CanRope = false; player.ClimbableObject = this; }
protected void OnTriggerStay(Collider other) { CharacterController cc = other.GetComponent <CharacterController>(); if (cc == null) { return; } bool isTopOfBox = JCS_Physics.TopOfBoxWithSlope(cc, mPlatformCollider); if (isTopOfBox) { Physics.IgnoreCollision( mPlatformCollider, cc, false); } else { Physics.IgnoreCollision( mPlatformCollider, cc, true); } JCS_2DSideScrollerPlayer p = other.GetComponent <JCS_2DSideScrollerPlayer>(); if (p == null) { return; } bool isJumpDown = p.IsDownJump(); if (!mCanBeDownJump) { // if cannot be down jump, fore it to false. isJumpDown = false; } if (p.CharacterState == JCS_2DCharacterState.CLIMBING || isJumpDown) { // IMPORTANT(JenChieh): Note that IgnoreCollision will reset // the trigger state of affected colliders, // so you might receive OnTriggerExit and // OnTriggerEnter messages in response to // calling this. Physics.IgnoreCollision( mPlatformCollider, p.GetCharacterController(), true); } if (isJumpDown && isTopOfBox) { if (JCS_PlatformSettings.instance != null) { /** * Make the player go down ward, so it will not stop by * the other collision detection. In order not to let the * render frame goes off. set the value as small as possible. */ p.VelY = -JCS_PlatformSettings.instance.POSITION_PLATFORM_DOWN_JUMP_FORCE; } else { JCS_Debug.Log( "No platform setting, could not set the down jump force..."); } } p.ResetingCollision = true; }