Jump() 공개 메소드

Try to jump
public Jump ( Jump j ) : void
j Jump
리턴 void
예제 #1
0
        public override void PerformAction(float delta)
        {
            Vector3 ori    = character.transform.position;
            Vector3 target = character.grab.GetCenter() - grabbingOffset;

            // once we center, stop moving!
            if (!centering)
            {
                character.velocity = Vector3.zero;
            }

            // close enough to our target position ?
            if (centering && Vector3.Distance(ori, target) < 0.1f)
            {
                character.velocity = target - ori;
                centering          = false;
            }
            // close the gap a little more
            if (centering)
            {
                // centering phase
                Vector3.SmoothDamp(
                    ori,
                    target,
                    ref character.velocity,
                    towardsTime,
                    towardsSpeed, //Mathf.Infinity,
                    delta);
            }

            character.SetFacing(input.GetAxisRawX());

            // check for dismount conditions
            if (dismountJumping && input.IsActionHeld(actionJump.action))
            {
                canGrab.Reset();
                character.ExitState(States.Grabbing);

                actionJump.Jump(new JumpConstant(character,
                                                 jumpOff.Clone((int)character.faceDir)
                                                 ));
            }
            else if (dismountPressingDown && input.GetAxisRawY() < 0)
            {
                // TODO Dismount down delay ?
                canGrab.Reset();
                character.ExitState(States.Grabbing);
            }
        }
예제 #2
0
        public override void PerformAction(float delta)
        {
            // guard: something goes wrong!
            Fence fence = character.fence;

            if (fence == null)
            {
                character.ExitState(States.Fence);
                return;
            }
            Vector2 in2d     = input.GetAxisRaw();
            Vector3 velocity = new Vector3(speed.x * in2d.x, 0, 0);

            // is difficult to move a Bound, so just move min/max point instead
            Bounds  b    = character.enterAreas.GetComponent <BoxCollider2D>().bounds;
            Vector3 pmin = b.min;
            Vector3 pmax = b.max;

            // test move X, if NOK do not move X
            if (!fence.body.Contains(pmin + velocity * delta, pmax + velocity * delta))
            {
                velocity.x = 0;
            }

            // test move Y, if NOK do not move Y
            velocity.y = speed.y * in2d.y;
            if (!fence.body.Contains(pmin + velocity * delta, pmax + velocity * delta))
            {
                velocity.y = 0;
            }

            character.velocity = velocity;
            character.SetFacing(in2d.x);

            // check for dismount conditions
            // do not allow to jump without telling the direction.
            // move up if you want it
            if (dismountJumping && input.IsActionHeld(actionJump.action))
            {
                //dismount.Reset();
                fence.Dismount(character);
                fence = null;

                actionJump.Jump(new JumpConstant(character,
                                                 jumpOff.Clone((int)character.faceDir)
                                                 ));
            }
        }
        /// <summary>
        /// </summary>
        public override void PerformAction(float delta)
        {
            Vector2 in2d = input.GetAxisRaw();

            float targetVelocityX = in2d.x * speed;

            character.velocity.x = Mathf.SmoothDamp(
                character.velocity.x,
                targetVelocityX,
                ref velocityXSmoothing,
                accelerationTime
                );

            // Debug.Log("-->" + character.liquid.IsBelowSurface(character, surfaceLevel));

            float d = character.liquid.DistanceToSurface(character, surfaceLevel);

            if (d > 0) // below
            {
                float factor = (1 + character.liquid.buoyancySurfaceFactor * d) * delta;
                //Debug.Log(factor);
                character.velocity.x += character.liquid.buoyancy.x * factor;
                character.velocity.y += character.liquid.buoyancy.y * factor;

                if (character.velocity.y > terminalYUP)
                {
                    character.velocity.y = terminalYUP;
                }
                if (character.velocity.y < -terminalYDown)
                {
                    character.velocity.y = terminalYDown;
                }
            }

            character.SetFacing(in2d.x);

            if (input.IsActionHeld(actionJump.action))
            {
                character.ExitState(States.Liquid);

                actionJump.Jump(new JumpConstant(character,
                                                 jumpOff.Clone((int)character.faceDir)
                                                 ));
            }
        }
        public override void PerformAction(float delta)
        {
            // guard: something goes wrong!
            if (character.ladder == null)
            {
                character.ExitState(States.Fence);
                return;
            }
            Ladder ladder = character.ladder;

            Vector2 in2d = input.GetAxisRaw();

            if (character.IsOnArea(Areas.Fence) && character.IsOnState(States.Fence))
            {
                // disable x movement
                character.velocity.x = 0;
                character.velocity.y = speed * in2d.y;
            }

            if (ladder.topDismount && ladder.IsAtTop(character, character.feet) && in2d.y > 0)
            {
                // top dismount enabled and reached
                character.velocity = Vector2.zero;
                ladder.Dismount(character);
            }
            else if (ladder.bottomDismount && ladder.IsAtBottom(character, character.feet) && in2d.y < 0)
            {
                // bottom dismount enabled and reached
                character.velocity = Vector2.zero;
                ladder.Dismount(character);
            }
            else if (!ladder.topDismount && ladder.IsAboveTop(character, character.head) && in2d.y > 0)
            {
                // can't dismount (vine) don't let the head 'overflow' the ladder
                character.velocity = Vector2.zero;
            }
            else if (!ladder.bottomDismount && ladder.IsAtBottom(character, character.feet) && in2d.y < 0)
            {
                // can't dismount (vine) don't let the head 'overflow' the ladder
                // caveat: Vine cannot be near ground
                character.velocity = Vector2.zero;
            }

            character.SetFacing(in2d.x);

            // check for dismount conditions
            if (in2d.x != 0)
            {
                // do not allow to jump without telling the direction.
                // move up if you want it
                if (dismountJumping && input.IsActionHeld(actionJump.action))
                {
                    dismount.Reset();
                    character.ladder.Dismount(character);
                    character.ladder = null;

                    actionJump.Jump(new JumpConstant(character,
                                                     jumpOff.Clone((int)character.faceDir)
                                                     ));
                }
                else if (dismount.IncReady())
                {
                    character.velocity = Vector2.zero;
                    character.ladder.Dismount(character);
                    character.ladder = null;
                }
            }
            else
            {
                dismount.Reset();
            }
        }
        public override void PerformAction(float delta)
        {
            // guard: something goes wrong!
            if (character.ladder == null)
            {
                character.ExitState(States.Ladder);
                return;
            }
            Ladder ladder = character.ladder;

            Vector2 in2d = input.GetAxisRaw();

            if (character.IsOnArea(Areas.Ladder) && character.IsOnState(States.Ladder))
            {
                // disable x movement
                character.velocity.x = 0;
                character.velocity.y = speed * in2d.y;
            }

            // TODO transition
            if (centering)
            {
                float ladderCenter = ladder.GetComponent <BoxCollider2D>().bounds.center.x;
                float characterX   = character.center.x;
                if (Math.Abs(characterX - ladderCenter) < 0.05)
                {
                    centering            = false;
                    character.velocity.x = 0;
                }
                else
                {
                    // instant move to the center of the ladder!
                    Mathf.SmoothDamp(characterX, ladderCenter, ref character.velocity.x, towardsTime, towardsSpeed, delta);
                }
            }

            if (ladder.topDismount && ladder.IsAtTop(character, character.feet) && in2d.y > 0)
            {
                // top dismount enabled and reached
                character.velocity = Vector2.zero;
                ladder.Dismount(character);
            }
            else if (ladder.bottomDismount && ladder.IsAtBottom(character, character.feet) && in2d.y < 0)
            {
                // bottom dismount enabled and reached
                character.velocity = Vector2.zero;
                ladder.Dismount(character);
            }
            else if (!ladder.topDismount && ladder.IsAboveTop(character, character.head) && in2d.y > 0)
            {
                // can't dismount (vine) don't let the head 'overflow' the ladder
                character.velocity = Vector2.zero;
            }
            else if (!ladder.bottomDismount && ladder.IsAtBottom(character, character.feet) && in2d.y < 0)
            {
                // can't dismount (vine) don't let the head 'overflow' the ladder
                // caveat: Vine cannot be near ground
                character.velocity = Vector2.zero;
            }

            character.SetFacing(in2d.x);

            // check for dismount conditions
            if (in2d.x != 0)
            {
                // do not allow to jump without telling the direction.
                // move up if you want it
                if (dismountJumping && input.IsActionHeld(actionJump.action))
                {
                    dismount.Reset();
                    character.ladder.Dismount(character);
                    character.ladder = null;

                    actionJump.Jump(new JumpConstant(character,
                                                     jumpOff.Clone((int)character.faceDir)
                                                     ));
                }
                else if (dismount.Ready())
                {
                    character.velocity = Vector2.zero;
                    character.ladder.Dismount(character);
                    character.ladder = null;
                }
            }
            else
            {
                dismount.Reset();
            }
        }
        public override void PerformAction(float delta)
        {
            Vector3 ori          = character.transform.position;
            Vector3 ropePosition = character.rope.sections[character.ropeIndex].GetComponent <RopeSection>().GetPositionInSection(positionOfSection);
            Vector3 target       = ropePosition + character.rope.faceDir * grabbingOffset;

            // close enough to our target position ?
            if (centering && Vector3.Distance(ori, target) < 0.1f)
            {
                character.velocity = target - ori;
                centering          = false;
            }
            else if (centering)
            {
                // centering phase: close the gap a little more
                Vector3.SmoothDamp(
                    ori,
                    target,
                    ref character.velocity,
                    towardsTime,
                    towardsSpeed, //Mathf.Infinity,
                    delta);
            }
            else
            {
                // once we center, follow the rope movement
                character.velocity = (target - ori) / delta;
            }

            // climb / descend the rope
            float offsetSeed = character.rope.SpeedToSectionOffset(climbSpeed) * delta;
            float y          = input.GetAxisRawY();

            if (y > 0)
            {
                positionOfSection = Mathf.Clamp01(positionOfSection + offsetSeed);
                if (positionOfSection == 1)
                {
                    // go to up if possible
                    if (character.ropeIndex != 0)
                    {
                        --character.ropeIndex;
                        positionOfSection = 0;
                    }
                }
            }
            else if (y < 0)
            {
                positionOfSection = Mathf.Clamp01(positionOfSection - offsetSeed);
                if (positionOfSection == 0)
                {
                    // go to up if possible
                    if (character.ropeIndex != character.rope.segments - 1)
                    {
                        ++character.ropeIndex;
                        positionOfSection = 1;
                    }
                    else
                    {
                        // TODO maybe we can dismount here :D
                    }
                }
            }


            // check for dismount conditions
            if (dismountJumping && input.IsActionHeld(actionJump.action))
            {
                canGrab.Reset();
                character.ExitState(States.Rope);

                actionJump.Jump(new JumpConstant(character,
                                                 jumpOff.Clone((int)character.faceDir)
                                                 ));
            }
        }
예제 #7
0
        public override void PerformAction(float delta)
        {
            ++slidingFrames;

            int   wallDirX = (pc2d.collisions.left) ? -1 : 1;
            float x        = input.GetAxisRawX();

            // terminal velocity
            // NOTE apply -gravity to compensate
            if (character.velocity.y < -wallSlideSpeedMax)
            {
                character.velocity.y = -wallSlideSpeedMax - character.pc2d.gravity.y * delta;
            }

            // TODO manage in frames
            if (timeToWallStickLeave > 0)
            {
                character.velocity.x = 0;

                if (x != wallDirX && x != 0)
                {
                    timeToWallStickLeave -= delta;
                }
                else
                {
                    timeToWallStickLeave = wallStickLeaveTime;
                }
            }
            else
            {
                timeToWallStickLeave = wallStickLeaveTime;
            }

            // Jump
            if (enableWallJumps && input.IsActionHeld(actionJump.action))
            {
                wallStickLeaveAgainCounter = 0; // reset!
                JumpConstant jump;
                character.ExitState(States.WallSliding);
                slidingFrames = 0;

                if (wallDirX == x)
                {
                    jump = new JumpConstant(character,
                                            wallJumpClimb.Clone(-wallDirX)
                                            );
                }
                else if (x == 0)
                {
                    jump = new JumpConstant(character,
                                            wallJumpOff.Clone(-wallDirX)
                                            );
                }
                else
                {
                    jump = new JumpConstant(character,
                                            wallLeap.Clone(-wallDirX)
                                            );
                }
                actionJump.Jump(jump);
            }
        }