コード例 #1
0
ファイル: NStateNormal.cs プロジェクト: EKomperud/H.E.R.O-2
    protected void PhysicsUpdate()
    {
        float x = 0;

        if (leftStick.x > 0)
        {
            x = rb.velocity.x > 0 ? rb.velocity.x : rb.velocity.x * directionSwitchRatio;
            x = Mathf.Min(x + (leftStick.x * 2.5f), maxLateralVelocity * Mathf.Abs(leftStick.x));
        }
        else if (leftStick.x < 0)
        {
            x = rb.velocity.x < 0 ? rb.velocity.x : rb.velocity.x * directionSwitchRatio;
            x = Mathf.Max(x + (leftStick.x * 2.5f), -maxLateralVelocity * Mathf.Abs(leftStick.x));
        }
        else if (GetBool("frozen"))
        {
            float sign = rb.velocity.x / Mathf.Abs(rb.velocity.x);
            x = Mathf.Abs(rb.velocity.x) > frozenSlideSpeed ? rb.velocity.x - (sign * 0.5f) : rb.velocity.x;
        }
        else
        {
            float sign = rb.velocity.x / Mathf.Abs(rb.velocity.x);
            x = Mathf.Abs(rb.velocity.x) > 1.5f ? rb.velocity.x - (sign * 1.2f) : 0f;
        }
        rb.velocity = new Vector2(x, -globalGravityPerFrame);

        movingPlatform = MovingPlatformCheck();
        if (movingPlatform != null)
        {
            rb.MovePosition(rb.position + movingPlatform.GetLastFrameMovement() + (rb.velocity * Time.fixedDeltaTime));
        }
    }
コード例 #2
0
    protected override void FixedUpdate()
    {
        if (activeWeapon)
        {
            if (held)
            {
                rightStick = new Vector2(joystick.GetAxis("Aim Horizontal"), joystick.GetAxis("Aim Vertical"));
                if (rightStick != Vector2.zero && this.Equals(wielder.GetWeapon()))
                {
                    UpdateAiming(rightStick);
                }
                else
                {
                    UpdateNotAiming();
                }
            }
            else
            {
                if (!decelerating)
                {
                    if ((_activeTime -= Time.fixedDeltaTime) <= 0)
                    {
                        decelerating = true;
                        wielder      = null;
                    }
                }
                else if (decelerating && !falling)
                {
                    rb.velocity *= decelerationFactor;
                    if (rb.velocity.sqrMagnitude <= 0.0025f)
                    {
                        falling         = true;
                        rb.velocity     = Vector2.zero;
                        rb.gravityScale = gravityScale;
                    }
                }
                else if (falling)
                {
                    BottomCheck();
                    if (GroundOrPlayerCheck())
                    {
                        // Reset state variables
                        animator.SetBool("gathering", false);
                        animator.SetBool("collided", true);
                        activeWeapon = false;
                        held         = false;
                        decelerating = false;
                        falling      = false;

                        // Reset reference variables
                        transform.rotation = new Quaternion();
                        rb.gravityScale    = 0f;
                        cc.isTrigger       = true;
                    }
                }
            }
        }
        else
        {
            BottomCheck();
            rb.velocity = GroundOrPlayerCheck() ? Vector2.zero : rb.velocity + gravityVector;
            mp          = MovingPlatformCheck();
            if (mp != null)
            {
                rb.MovePosition(rb.position + mp.GetLastFrameMovement() + (rb.velocity * Time.fixedDeltaTime));
            }
        }
    }