Ejemplo n.º 1
0
    // On Dash End
    private void OnDashEnd()
    {
        // Ray to check if we are still sliding under something
        RaycastHit2D ceilingRay = Physics2D.Raycast(new Vector2(boxCollider.bounds.center.x, boxCollider.bounds.min.y),
                                                    Vector2.up, rStandBounds.height, motor.staticEnvLayerMask | motor.movingPlatformLayerMask);
        RaycastHit2D floorRay = Physics2D.Raycast(transform.position, Vector2.down, 0.05f, motor.staticEnvLayerMask | motor.movingPlatformLayerMask);

        // If ray hits environment, slide until we are out of the tunnel
        if (ceilingRay.collider != null && floorRay.collider != null)
        {
            motor.dashDuration       = 0.05f;
            motor.dashDistance       = 1;
            motor.dashEasingFunction = PC2D.EasingFunctions.Functions.Linear;
            motor.ResetDashCooldown();
            motor.Dash();
            motor.ReupdateVelocity();

            bSliding = true;

            return;
        }

        // Reset dash variables
        motor.dashEasingFunction = dashEasing;
        motor.dashDuration       = fDashTime;
        motor.dashDistance       = fDashDistance;

        // Change collision shape to match state
        if (bCrouching)
        {
            collisionShape = ePlayerCollisionShape.Crouch;
        }
        else
        {
            collisionShape = ePlayerCollisionShape.Standard;
        }

        bSliding = false;
    }
Ejemplo n.º 2
0
    // Checks for Movement Input and applies it to the motor
    private void HandleMovementInput()
    {
        if (bPlayerControlDisabled)
        {
            return;
        }

        // If movement is disabled, return
        if (bMovementDisabled)
        {
            motor.normalizedXMovement = 0;
            motor.normalizedYMovement = 0;

            return;
        }

        if (!bWallJumping)
        {
            // Horizontal Axis
            motor.normalizedXMovement = playerInput.GetAxis("Movement Horizontal");
            // Vertical Axis
            motor.normalizedYMovement = playerInput.GetAxis("Movement Vertical");
        }

        // Crouching
        if (playerInput.GetAxis("Movement Vertical") < -0.8f && Mathf.Abs(motor.normalizedXMovement) < 0.4f)
        {
            if (motor.motorState == PlatformerMotor2D.MotorState.OnGround)
            {
                motor.normalizedXMovement = 0;
                collisionShape            = ePlayerCollisionShape.Crouch;
                bCrouching = true;
            }
            else
            {
                if (!bSliding)
                {
                    collisionShape = ePlayerCollisionShape.Standard;
                }

                bCrouching = false;
            }
        }
        else
        {
            if (!bSliding)
            {
                collisionShape = ePlayerCollisionShape.Standard;
            }

            bCrouching = false;
        }

        // If on wall or corner and conditions for walljumping is met then enable walljumpready
        if (bOnWall || bOnCorner)
        {
            if ((bLastWallCollisionDirLeft && motor.normalizedXMovement >= 0.1f) ||
                (!bLastWallCollisionDirLeft && motor.normalizedXMovement <= -0.1f))
            {
                bWallJumpReady = true;
            }
            else
            {
                bWallJumpReady = false;
            }
        }
        else
        {
            bWallJumpReady = false;
        }

        // Jumping
        if (playerInput.GetButtonDown("Jump"))
        {
            if (playerInput.GetAxis("Movement Vertical") < -0.25f)
            {
                if (motor.motorState == PlatformerMotor2D.MotorState.OnGround)
                {
                    bool ghostJump = GhostJump();

                    if (!ghostJump)
                    {
                        motor.Jump();
                    }
                }
                else
                {
                    motor.Jump();
                }
            }
            else
            {
                motor.Jump();
            }
        }

        // Variable Jump Height
        motor.jumpingHeld = playerInput.GetButton("Jump");

        // Dashing
        if (playerInput.GetButtonDown("Dash"))
        {
            if (motor.canDash)
            {
                if (motor.motorState != PlatformerMotor2D.MotorState.ClimbingCorner)
                {
                    // If On Ground, Jumping or Falling
                    if (motor.motorState == PlatformerMotor2D.MotorState.OnGround ||
                        motor.motorState == PlatformerMotor2D.MotorState.Jumping ||
                        motor.motorState == PlatformerMotor2D.MotorState.Falling)
                    {
                        // Check velocity and aim direction
                        if (Mathf.Abs(motor.velocity.x) < 0.1f && motor.canDash)
                        {
                            // If aiming then set motor direction to aiming direction
                            if (bAimState)
                            {
                                motor.facingLeft = v2PrevAimDiff.x >= 0 ? true : false;
                            }
                        }
                    }

                    // If Slide Method is Down + Dash
                    if (GlobalSettings.iSlideInputMethod == 0)
                    {
                        if (playerInput.GetAxis("Movement Vertical") < -0.4f)
                        {
                            if (motor.motorState == PlatformerMotor2D.MotorState.OnGround)
                            {
                                collisionShape = ePlayerCollisionShape.Slide;
                                bSliding       = true;
                            }
                        }
                    }

                    motor.Dash();

                    if (onDash != null)
                    {
                        onDash();
                    }
                }
            }
        }

        // If Slide Input Method is set to Own Input
        if (GlobalSettings.iSlideInputMethod == 1)
        {
            if (playerInput.GetButtonDown("Slide"))
            {
                if (motor.canDash && motor.motorState == PlatformerMotor2D.MotorState.OnGround)
                {
                    collisionShape = ePlayerCollisionShape.Slide;
                    bSliding       = true;

                    motor.Dash();

                    if (onDash != null)
                    {
                        onDash();
                    }
                }
            }
        }

        // Walk
        if (!bOnWall && !bOnCorner)
        {
            if (playerInput.GetButton("Walk") || bForceWalk)
            {
                motor.normalizedXMovement = Mathf.Clamp(motor.normalizedXMovement, -0.25f, 0.25f);
            }
        }
    }
Ejemplo n.º 3
0
    // Update
    void Update()
    {
        // If game paused or player control is disabled, return
        if (GameManager.GamePaused)
        {
            return;
        }

        // Motor State and Movement Input
        HandleMotorState();
        HandleMovementInput();

        // If any weapons are equipped, update weapon state
        if (lWeapons.Count > 0)
        {
            HandleWeaponState();
            HandleWeaponInput();
            HandleWeaponAimInput();
        }

        // If collision shape has changed, change collider bounds
        if (collisionShape != prevCollisionShape)
        {
            switch (collisionShape)
            {
            case ePlayerCollisionShape.Standard:     // Standard bounds
                // Previous Bounds
                Bounds prevBounds = boxCollider.bounds;
                // Raycast for ceiling checking
                RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.up, rStandBounds.size.y,
                                                     motor.staticEnvLayerMask | motor.movingPlatformLayerMask, 0);

                // If clipping could occur, push away by distance
                if (hit.collider != null)
                {
                    StartCoroutine(TweenColliderSize(rStandBounds.size, rStandBounds.position, 0.25f));
                }
                else
                {
                    boxCollider.size   = rStandBounds.size;
                    boxCollider.offset = rStandBounds.position;
                }
                break;

            case ePlayerCollisionShape.Crouch:     // Crouch Bounds
                boxCollider.size   = rCrouchBounds.size;
                boxCollider.offset = rCrouchBounds.position;
                break;

            case ePlayerCollisionShape.Slide:     // Slide Bounds
                boxCollider.size   = rSlideBounds.size;
                boxCollider.offset = rSlideBounds.position;
                break;
            }
        }

        // If facing direction has changed by end of update, change weapon hand
        if (bFacingLeft != bPrevFacingLeft)
        {
            animator.FlipCharacter();
            StartCoroutine(SwitchWeaponHand());
        }

        // TEMP - Display current aim angle difference to target
        if (Input.GetKeyDown(KeyCode.B))
        {
            print(animator.weaponPivotIKBone.GetWorldPosition(animator.transform).x);
        }

        if (Input.GetKeyDown(KeyCode.M))
        {
            GetComponent <HealthManager>().TakeHealth(10);
        }

        if (Input.GetKeyDown(KeyCode.K))
        {
            GetComponent <HealthManager>().GiveHealth(10);
        }

        bPrevFacingLeft    = bFacingLeft;
        prevCollisionShape = collisionShape;
    }