Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (hitstopTime >= 0f)
        {
            hitstopTime -= Time.deltaTime;
            return;
        }
        this.animator.enabled = true;

        playerInput.GatherInput();
        collisionInfo = controller.GetCollisions();
        PlayerState prevState = state;

        state = state.Tick(this);
        if (state != prevState)
        {
            prevState.OnStateExit(this);
            state.OnStateEnter(this);
        }
    }
Example #2
0
    public override PlayerState Tick(PlayerController context)
    {
        LagueController2D.CollisionInfo collisionInfo = context.GetCollisionInfo();
        PlayerInput playerInput = context.GetPlayerInput();

        if (!collisionInfo.below)
        {
            return(new StateAirborne());
        }

        if (playerInput.GetDidPressJump())
        {
            context.velocity.y = context.GetMaxJumpVelocity();
            return(new StateAirborne());
        }

        if (playerInput.GetDidPressAttack())
        {
            return(new StateAttacking());
        }

        PlayerInput input = context.GetPlayerInput();

        if (input.GetDidPressGrapple() && input.GetAimDirection().y > 0)
        {
            context.GetGrappleHook().SetDirection(input.GetAimDirection());
            return(new StateGrappling());
        }

        float horizInput      = playerInput.GetHorizInput();
        float targetVelocityX = horizInput * context.GetSpeed();

        context.velocity.x = Mathf.SmoothDamp(context.velocity.x, targetVelocityX, ref context.velocityXSmoothing, context.GetVelocityXSmoothFactorGrounded());
        context.velocity.y = context.GetGravity() * Time.deltaTime;

        context.FaceVelocityX();
        context.GetController().Move(context.velocity * Time.deltaTime);

        return(this);
    }
Example #3
0
    public override PlayerState Tick(PlayerController context)
    {
        GrappleHook grappleHook = context.GetGrappleHook();

        GrappleHook.State grappleHookState = grappleHook.GetState;

        Vector2 grappleEndPos = grappleHook.GetEndingPosition();
        Vector2 curPosition   = context.transform.position;

        LagueController2D.CollisionInfo collisionInfo = context.collisionInfo;
        float directionX = Mathf.Sign(grappleEndPos.x - curPosition.x);

        float directionY = Mathf.Sign(grappleEndPos.y - curPosition.y);

        if (directionY == 1 && collisionInfo.above || directionY == -1 && collisionInfo.below)
        {
            EndGrapple(context);
            return(context.GetDefaultState());
        }

        if (directionX == 1 && collisionInfo.right || directionX == -1 && collisionInfo.left)
        {
            EndGrapple(context);
            return(new StateWallCling());
        }

        float   targetVelocity = context.GetReelSpeed();
        Vector2 direction      = (grappleEndPos - curPosition) * targetVelocity;

        // context.velocity.x = Mathf.SmoothDamp(context.velocity.x, targetVelocityX, ref context.velocityXSmoothing, context.GetVelocityXSmoothFactorGrounded());
        // context.velocity.y = context.GetGravity() * Time.deltaTime;
        context.velocity.x = direction.x;
        context.velocity.y = direction.y;

        context.FaceVelocityX();
        context.GetController().Move(context.velocity * Time.deltaTime);

        return(this);
    }