示例#1
0
 private void FixedUpdate()
 {
     if (Input.GetAxisRaw("Horizontal") == 1)
     {
         pc.Move(1, false, false);
     }
     if (Input.GetAxisRaw("Horizontal") == -1)
     {
         pc.Move(-1, false, false);
     }
     if (Input.GetKeyDown("space"))
     {
         pc.Move(1, false, true);
     }
 }
    private void Update()
    {
        input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

        if ((Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown("joystick button 0")) && controller.collisions.below)
        {
            Jump();
        }
        if (Input.GetKeyUp(KeyCode.Space) || Input.GetKeyUp("joystick button 0"))
        {
            JumpRelease();
        }

        CalculatePlayerVelocity();
        controller.Move(velocity * Time.deltaTime, input);
        if (controller.collisions.above || controller.collisions.below)
        {
            if (controller.collisions.slidingDownMaxSlope)
            {
                velocity.y += controller.collisions.slopeNormal.y * -gravity * Time.deltaTime;
            }
            else
            {
                velocity.y = 0;
            }
        }
        if ((controller.collisions.left || controller.collisions.right) && !controller.collisions.slidingDownMaxSlope)
        {
            velocity.x = 0;
        }
    }
示例#3
0
    // Update is called once per frame
    void Update()
    {
        if (controller.collisions.above || controller.collisions.below)
        {
            velocity.y = 0;
        }
        //left and right movement input
        Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal" + playerNumber), Input.GetAxisRaw("Vertical" + playerNumber));

        //jump input
        if (Input.GetButtonDown("Jump" + playerNumber) && (jumpsLeft != 0))
        {
            velocity.y = jumpVelocity;
            jumpsLeft--;
        }
        // apply gravity & movement

        float targetVelocityX = input.x * moveSpeed;

        velocity.x  = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below)?accelerationTimeGrounded:accelerationTimeAirborn);
        velocity.y += gravity * Time.deltaTime;

        //apply velocity to the character
        controller.Move(velocity * Time.deltaTime);


        if (controller.collisions.below)
        {
            jumpsLeft = maxJumps;
        }

        if (Input.GetButtonDown("Fire" + playerNumber))
        {
            switch (currentPowerUp)
            {
            case PowerUp.Pistol: FirePistol();
                break;

            case PowerUp.Crossbow: FireArrow();
                break;
            }
        }
//		if(Input.GetButtonDown("Melee" + playerNumber)) {

        //	}

        if (velocity.x != 0)
        {
            if (Mathf.Sign(velocity.x) == 1)
            {
                isFacingRight = true;
            }
            else
            {
                isFacingRight = false;
            }
        }
    }
示例#4
0
    void Moving()
    {
        Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

        velocity.y += gravity * Time.deltaTime;
        velocity.x  = input.x * moveSpeed;
        FlipSprite(input);
        AnimateRunning(input);
        controller.Move(velocity * Time.deltaTime);
    }
示例#5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (dead)
        {
            return;
        }

        moveVector.y = Mathf.Max(moveVector.y - movement.gravity * Time.deltaTime, -movement.gravity);
        playerController2D.Move(moveVector * Time.deltaTime);
        playerController2D.CheckCollisionDown();
    }
示例#6
0
    // Update is called once per frame
    void Update()
    {
        if (controller.collisions.above || controller.collisions.below)
        {
            velocity.y = 0;
        }
        //left and right movement input
        Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal" + playerNumber), Input.GetAxisRaw("Vertical" + playerNumber));

        //jump input
        if (Input.GetButtonDown("Jump" + playerNumber) && (jumpsLeft != 0))
        {
            velocity.y = jumpVelocity;
            jumpsLeft--;
        }
        // apply gravity & movement

        float targetVelocityX = input.x * moveSpeed;

        velocity.x  = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below)?accelerationTimeGrounded:accelerationTimeAirborn);
        velocity.y += gravity * Time.deltaTime;

        //apply velocity to the character
        controller.Move(velocity * Time.deltaTime);


        if (controller.collisions.below)
        {
            jumpsLeft = maxJumps;
        }

        if (Input.GetButtonDown("Fire" + playerNumber))
        {
            firedProjectile = Instantiate(projectile, transform.position, transform.rotation) as GameObject;
            firedProjectile.GetComponent <Rigidbody2D>().AddForce(new Vector2((isFacingRight?1:-1) * 1000, 0));
            Physics2D.IgnoreCollision(firedProjectile.GetComponent <Collider2D>(), GetComponent <Collider2D>());
        }
        if (velocity.x != 0)
        {
            if (Mathf.Sign(velocity.x) == 1)
            {
                isFacingRight = true;
            }
            else
            {
                isFacingRight = false;
            }
        }
    }
示例#7
0
    private void FixedUpdate()
    {
        if (rb2d.velocity.y < 0)
        {
            rb2d.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.fixedDeltaTime;
        }
        else if (rb2d.velocity.y > 0)
        {
            rb2d.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.fixedDeltaTime;
        }

        //move character
        if (!lockMovement)
        {
            cc.Move(horizontalMove * Time.fixedDeltaTime, jump);
        }
        jump = false;
    }
示例#8
0
    // Update is ca   lled once per frame
    void FixedUpdate()
    {
        if (dead)
        {
            return;
        }

        moveVector.y = Mathf.Max(moveVector.y - movement.gravity * Time.deltaTime, -movement.gravity);

        playerController2D.Move(moveVector * Time.deltaTime);

        playerController2D.CheckCollisionDown();

        if (timeLastLostTarget > 0.0f)
        {
            timeLastLostTarget -= Time.deltaTime;
        }

        if (timeLostShootRate > 0.0f)
        {
            timeLostShootRate -= Time.deltaTime;
        }
    }
示例#9
0
    void FixedUpdate()
    {
        // Anything related to MOVEMENT/PHYSICS goes HERE!

        CalcVelocity();
        Crouch();

        controller.Move(velocity * Time.deltaTime);

        if (controller.collisions.above || controller.collisions.below)
        {
            if (controller.collisions.slideMaxSlope)
            {
                velocity.y += controller.collisions.slopeNormal.y * -gravity * Time.deltaTime;
            }
            else
            {
                velocity.y = 0;
            }
        }

        if (directInput.x > 0 && !faceRight)
        {
            Flip();
        }
        else if (directInput.x < 0 && faceRight)
        {
            Flip();
        }

        if (grabbing)
        {
            Hold();
        }

        inAir = !controller.collisions.below;   // This is here for animation purposes.
    }
    void Update()
    {
        if (Input.GetAxis("Horizontal") != 0 || Input.GetButtonDown("Jump"))
        {
            _playerTookControl = true;
        }

        if (!_playerTookControl)
        {
            if (Time.time >= _timeForJump)
            {
                _jump = true;
            }

            var input = Vector2.zero;
            if (Time.time >= _timeForMove)
            {
                input.x = _dir;
            }

            _player.Move(input, _jump);
            _jump = false;
        }
    }
示例#11
0
    void Update()
    {
        lancer = GetComponent <Health>().heartBar.throwing;
        if (courseDroite)
        {
            transform.localScale = new Vector3(actualScale, transform.localScale.y, transform.localScale.z);
        }
        else
        {
            transform.localScale = new Vector3(-actualScale, transform.localScale.y, transform.localScale.z);
        }

        float targetVelocityX;

        hurtTimer += Time.deltaTime;

        if (hurtTimer >= hurtCooldown)
        {
            if (playerState == PlayerState.HealthBar)
            {
                SetRepos();
            }
            else
            {
                SetHeartRepos();
            }


            if (controller.collisions.above || controller.collisions.below)
            {
                velocity.y = 0;
            }

            Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
            if (Input.GetAxisRaw("Horizontal") != 0)
            {
                if (playerState == PlayerState.HealthBar)
                {
                    SetCourse();
                }
                else
                {
                    SetHeartCourse();
                }
                if (Input.GetAxisRaw("Horizontal") > 0)
                {
                    courseDroite = true;
                }
                else
                {
                    courseDroite = false;
                }
            }


            if (Input.GetButtonDown("Jump") && controller.collisions.below)
            {
                velocity.y = jumpVelocity;
                if (playerState == PlayerState.HealthBar)
                {
                    SetSaut();
                }
                else
                {
                    SetHeartSaut();
                }
            }

            targetVelocityX = input.x * moveSpeed;
            velocity.x      = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirborne);
        }
        else
        {
            targetVelocityX = 0f;
        }

        velocity.x  = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirborne);
        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);
    }
示例#12
0
 void FixedUpdate()
 {
     //
     controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
     jump = false;
 }
示例#13
0
    private void FixedUpdate()
    {
        if (!isDead)
        {
            if (rb.velocity.y < 0)
            {
                rb.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1);
            }
            else if (rb.velocity.y > 0)
            {
                rb.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 0.8f);
            }

            //print(jump);

            if (jump && cc.m_jumpCount < maxNumberOfJumps && rb.velocity.y < 0 && !recentlyAttacked)
            {
                rb.velocity = Vector2.zero;
            }

            //move character
            if (!lockMovement && !specialJump)
            {
                cc.Move(horizontalMove, jump && cc.m_jumpCount < maxNumberOfJumps);

                if (cc.m_jumpCount > 0 && jump)
                {
                    doubleJumpUsed = true;
                }

                if (cc.m_doubleJumpEnabled)
                {
                    if (cc.m_jumpCount < 1)
                    {
                        //jumpCount++;
                    }
                }

                if (cc.m_jumpCount > 1)
                {
                    cc.m_doubleJumpUsed = doubleJumpUsed = true;
                }
            }
            else if (!lockMovement && specialJump)
            {
                if (isLeaping)
                {
                    print("is leaping");
                    Leap();
                }
                else if (isBackLeaping)
                {
                    BackLeap();
                }
                else if (isBackStepping)
                {
                    BackStep();
                }
            }
        }


        jump           = false;
        horizontalMove = 0;
    }
示例#14
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Melee" + playerNumber) && meleeTimer == 0)
        {
            upperAnimator.SetTrigger("MeleeAttack");
//			meleeHitbox.enabled = true;
        }

        if (controller.collisions.above || controller.collisions.below)
        {
            velocity.y = 0;
        }

        if (controller.collisions.below)
        {
            lowerAnimator.SetBool("isJumping", false);
            isJumping = false;
        }
        //left and right movement input
        Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal" + playerNumber), Input.GetAxisRaw("Vertical" + playerNumber));

        //jump input
        if (Input.GetButtonDown("Jump" + playerNumber) && (jumpsLeft != 0))
        {
            velocity.y = jumpVelocity;
            jumpsLeft--;
            lowerAnimator.SetBool("isJumping", true);
            isJumping = true;
        }
        // apply gravity & movement

        float targetVelocityX = input.x * moveSpeed;

        velocity.x = targetVelocityX;
        //velocity.x = Mathf.SmoothDamp( velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below)?accelerationTimeGrounded:accelerationTimeAirborn);
        velocity.y += gravity * Time.deltaTime;



        if (Input.GetButtonDown("Fire" + playerNumber))
        {
            switch (currentPowerUp)
            {
            case PowerUp.Pistol: FirePistol();
                upperAnimator.SetTrigger("ShootPistol");
                break;

            case PowerUp.Crossbow: FireArrow();
                upperAnimator.SetTrigger("ShootCrossbow");
                break;

            case PowerUp.Blink: Blink();
                break;

            default: break;
            }
        }
        if (shieldOn == true && currentPowerUp == PowerUp.Shield && powerUpUsesLeft == 0)
        {
            ToggleShield();
        }

        if (shieldOn == true && currentPowerUp != PowerUp.Shield)
        {
            ToggleShield();
        }

        if (currentPowerUp == PowerUp.Shield && shieldOn == false && powerUpUsesLeft == 3)
        {
            ToggleShield();
        }

        if (velocity.x != 0)
        {
            if (velocity.x > 0)
            {
                if (isFacingRight != true)
                {
                    oldDirection  = isFacingRight;
                    isFacingRight = true;
                    flip();
                }
            }
            else if (velocity.x < 0)
            {
                if (isFacingRight != false)
                {
                    oldDirection  = isFacingRight;
                    isFacingRight = false;
                    flip();
                }
            }
        }

        if (knockbackBuffer.x != 0 && knockbackBuffer.y != 0)
        {
            velocity.x        += knockbackBuffer.x / 10;
            velocity.y        += knockbackBuffer.y / 10;
            knockbackBuffer.x -= knockbackBuffer.x / 10;
            knockbackBuffer.y -= knockbackBuffer.y / 10;
        }

        if (transform.localScale.x > 0)
        {
            if (controller.collisions.right == false)
            {
                controller.Move(velocity * Time.deltaTime, transform.localScale.x);
            }
            else
            {
                velocity.x = 0;
                controller.Move(velocity * Time.deltaTime, transform.localScale.x);
            }
        }
        else if (transform.localScale.x < 0)
        {
            if (controller.collisions.left == false)
            {
                velocity.x *= -1;
                controller.Move(velocity * Time.deltaTime, transform.localScale.x);
            }
            else
            {
                velocity.x = 0;
                controller.Move(velocity * Time.deltaTime, transform.localScale.x);
            }
        }
        else
        {
            controller.Move(velocity * Time.deltaTime, 1);
        }
        if (velocity.x != 0 && isJumping == false)
        {
            lowerAnimator.SetBool("isWalking", true);
            //Debug.Log("yo");
        }
        else
        {
            lowerAnimator.SetBool("isWalking", false);
            //Debug.Log("yo2");
        }
        //apply velocity to the character
        //controller.Move(velocity * Time.deltaTime);



        if (controller.collisions.below)
        {
            jumpsLeft = maxJumps;
        }
    }
    void Update()
    {
        anim.SetBool("Land", false);
        anim.SetBool("Fall", false);

        Vector2 input = PlayerInput.GetDirectionalInput();

        int   wallDirectionX = (controller.collisions.left) ? -1 : 1;
        float targetVelocityX;

        targetVelocityX = input.x * moveSpeed;
        velocity.x      = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocitySmoothingX, (controller.collisions.below) ? accelerationGrounded : accelerationTimeAirborne);

        if (PlayerInput.GetFlyDown())
        {
            flying           = true;
            timeFlyInitiated = Time.time;
            anim.SetTrigger("Flying");
        }
        if (flying && (PlayerInput.GetFlyUp() || Time.time - timeFlyInitiated > maxFlyTime))
        {
            flying = false;
            anim.SetTrigger("FlyingRelease");
        }

        if (flying)
        {
            velocity.y = Mathf.Lerp(velocity.y, flyStrength + flySinStrength * Mathf.Sin((Time.time - timeFlyInitiated) * 4f * Mathf.PI), 4f * (Time.time - timeFlyInitiated));
            if (velocity.y > maxFlySpeed)
            {
                velocity.y = maxFlySpeed;
            }
        }


        bool wallSliding = false;

        if (controller.collisions.left || controller.collisions.right && !controller.collisions.below && velocity.y < 0)
        {
            wallSliding = true;

            if (velocity.y < -wallSlideSpeedMax)
            {
                velocity.y = -wallSlideSpeedMax;
            }

            if (timeToWallUnstick > 0)
            {
                velocitySmoothingX = 0f;
                velocitySmoothingY = 0f;
                velocity.x         = 0f;

                if (input.x != wallDirectionX && input.x != 0f)
                {
                    timeToWallUnstick -= Time.deltaTime;
                }
                else
                {
                    timeToWallUnstick = wallStickTime;
                }
            }
            else
            {
                timeToWallUnstick = wallStickTime;
            }
        }


        if (controller.collisions.above && velocity.y > 0)
        {
            velocity.y = 0f;
        }

        if (PlayerInput.GetJumpDown())
        {
            if (wallSliding)
            {
                if (wallDirectionX == input.x)
                {
                    velocity.x = -wallDirectionX * wallJumpClimb.x;
                    velocity.y = wallJumpClimb.y;
                }
                else if (velocity.x == 0f)
                {
                    velocity.x = -wallDirectionX * wallJumpOff.x;
                    velocity.y = wallJumpOff.y;
                }
                else
                {
                    velocity.x = -wallDirectionX * wallLeap.x;
                    velocity.y = wallLeap.y;
                }
                TriggerJump();
                canDoubleJump = true;
            }

            if (controller.collisions.below)
            {
                velocity.y    = maxJumpVelocity;
                canDoubleJump = true;
                TriggerJump();
            }
            else if (canDoubleJump && !wallSliding)
            {
                velocity.y    = (maxJumpVelocity + minJumpVelocity) / 2f;
                canDoubleJump = false;
                TriggerJump();
            }
        }
        if (PlayerInput.GetJumpUp())
        {
            if (velocity.y > minJumpVelocity)
            {
                velocity.y = minJumpVelocity;
            }
        }


        if (controller.collisions.below)
        {
            TriggerLand();
        }
        else if (!flying)
        {
            TriggerFall();
        }

        velocity.y += gravity * Time.deltaTime * ((velocity.y < 0f) ? fastFallGravityModifier : 1f);
        if (velocity.y < -maxFallingSpeed)
        {
            velocity.y = -maxFallingSpeed;
        }

        controller.Move(velocity * Time.deltaTime);

        anim.SetFloat("VelocityX", (Mathf.Abs(velocity.x) < 0) ? 0 : (Mathf.Abs(velocity.x) > 1 ? 1 : Mathf.Abs(velocity.x)));
        anim.SetFloat("VelocityY", velocity.y);
    }
 private void FixedUpdate()
 {
     _controller.Move(_horizontalMove * Time.fixedDeltaTime, _crouch, _jump);
     _jump = false;
 }