EnableLadder() public method

Notify Character is on ladder area
public EnableLadder ( Character p ) : void
p Character
return void
        /// <summary>
        /// Enter in ladder mode when user is in a ladder area and pressing up/down
        /// </summary>
        public override int WantsToUpdate(float delta)
        {
            bool onLadderState = character.IsOnState(States.Ladder);
            bool onLadderArea  = character.IsOnArea(Areas.Ladder);
            // this means below my feet there is a ladder
            Ladder ladder = null;

            if (!onLadderArea && character.ladderBottom)
            {
                // deferred logic
                // if you EnableLadder now, you enter an area but there is no 'outisde-check'
                // so defer logic until also press down.
                onLadderArea = true;
                ladder       = character.ladderBottom;
            }

            // in ladder state
            if (onLadderState)
            {
                return(priority);
            }

            bool enter = false;

            // enter ladder condition
            if (onLadderArea && !onLadderState && (ladder != null || character.ladder != null))
            {
                float dir = input.GetAxisRawY();
                // moving up, while inside a real LadderArea.
                if (dir > 0 && !(ladder ?? character.ladder).IsAtTop(character, character.feet))
                {
                    enter = true;
                }
                else if (dir < 0 && !(ladder ?? character.ladder).IsAtBottom(character, character.feet))
                {
                    // moving down: entering from the top
                    if (ladder != null)
                    {
                        ladder.EnableLadder(character);

                        // move the player inside the ladder.
                        Vector3 pos = character.gameObject.transform.position;
                        character.gameObject.transform.position = pos;

                        enter = true;
                    }
                    else
                    {
                        // moving down: entering from the middle-bottom

                        // check feet/bottom
                        float bottomLadderY = character.ladder.GetBottom().y;
                        float feetY         = character.feet.y;

                        // do not enter the ladder while on ground - pressing down
                        if (feetY > bottomLadderY)
                        {
                            enter = true;
                        }
                    }
                }
            }

            if (enter)
            {
                return(priority);
            }

            return(0);
        }
Example #2
0
        /// <summary>
        /// Enter in ladder mode when user is in a ladder area and pressing up/down
        /// </summary>
        public override int WantsToUpdate(float delta)
        {
            bool onLadderState = character.IsOnState(States.Ladder);
            bool onLadderArea  = character.IsOnArea(Areas.Ladder);
            // this means below my feet there is a ladder
            Ladder ladder = null;

            if (!onLadderArea)
            {
                // check out feet, maybe there is a ladder below...
                RaycastHit2D hit = pc2d.DoFeetRay(
                    pc2d.skinWidth * 2,
                    Configuration.instance.laddersMask
                    );
                if (hit)
                {
                    ladder = hit.collider.gameObject.GetComponent <Ladder>();
                    if (ladder == null)
                    {
                        Debug.LogWarning(hit.collider.gameObject + " in ladder mask don't have a Ladder component!");
                    }
                    else
                    {
                        Debug.Log("below there is a ladder!!");
                        // deferred logic
                        // if you EnableLadder now, you enter an area but there is no 'outisde-check'
                        // so defer logic until also press down.
                        onLadderArea = true;
                    }
                }
            }

            // in ladder state
            if (onLadderState)
            {
                return(priority);
            }

            bool enter = false;

            // enter ladder condition
            if (onLadderArea && !onLadderState && (ladder != null || character.ladder != null))
            {
                float dir = input.GetAxisRawY();
                // moving up, while inside a real LadderArea.
                if (dir > 0 && !(ladder ?? character.ladder).IsAtTop(character, character.feet))
                {
                    enter = true;
                }
                else if (dir < 0 && !(ladder ?? character.ladder).IsAtBottom(character, character.feet))
                {
                    // moving down: entering from the top
                    if (ladder != null)
                    {
                        ladder.EnableLadder(character);

                        // move the player inside the ladder.
                        Vector3 pos = character.gameObject.transform.position;
                        character.gameObject.transform.position = pos;

                        enter = true;
                    }
                    else
                    {
                        // moving down: entering from the middle-bottom

                        // check feet/bottom
                        float bottomLadderY = character.ladder.GetBottom().y;
                        float feetY         = character.feet.y;

                        // do not enter the ladder while on ground - pressing down
                        if (feetY > bottomLadderY)
                        {
                            enter = true;
                        }
                    }
                }
            }

            if (enter)
            {
                return(priority);
            }

            return(0);
        }