protected override void Update()
 {
     base.Update();
     transform.position = target.position + offset;
     transform.rotation = Quaternion.Euler(new Vector3(0, 0, ActionInput.GetJoyconVector().y + startAngle));
     //rb.MoveRotation(ActionInput.GetJoyconVector().y + startAngle);
 }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        //Quaternion orientation = m_joyconR.GetVector();
        //orientation = new Quaternion(orientation.w, orientation.y, orientation.z, orientation.x);

        // eulerAnglesで3次元に変換してから
        Vector3 orientation = ActionInput.GetJoyconVector();
        Vector3 angles      = transform.localEulerAngles;

        //angles.x = -orientation.x;
        //angles.y = orientation.z + 180;
        angles.z = orientation.y + 180;
        //Debug.LogFormat("x:{0}, y:{1}, z:{2}", orientation.x, orientation.z + 180, orientation.y + 180);
        //transform.localEulerAngles = angles;


        //そのままQuartanionで
        //Quaternion orientation = m_joyconR.GetVector();
        //orientation = new Quaternion(orientation.w, orientation.y, orientation.z, orientation.x);


        // ジャイロで
        //Vector3 gyro = m_joyconR.GetGyro();
        //Debug.Log(gyro);

        foreach (Transform child in transform)
        {
            // ジョイコンの傾きを同期させる
            //child.transform.rotation = orientation;
            child.transform.localEulerAngles = angles;

            //child.transform.Rotate(-gyro.y * 1f, gyro.x * 1f, -gyro.z * 1f);
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        /*if (m_joyconR == null)
         * {
         *  var joycons = JoyconManager.Instance.j;
         *  m_joyconR = joycons.Find(c => !c.isLeft);
         *  return;
         * }*/

        //Vector3 orientation = m_joyconR.GetVector().eulerAngles;
        Vector3 orientation = ActionInput.GetJoyconVector();
        Vector3 angles      = transform.localEulerAngles;

        angles.z = orientation.y;
        transform.localEulerAngles = angles + new Vector3(0f, 0f, 90f);

        wingAngle          = transform.localRotation.eulerAngles.z;
        transform.position = new Vector3(playerTrfm.position.x + distanceFromPlayer * Mathf.Cos(wingAngle / 180f * Mathf.PI),
                                         distanceFromPlayer * Mathf.Sin(wingAngle / 180f * Mathf.PI), 0f);
        //transform.Rotate(0.5f, 0f, 0f);

        /*if (m_joyconR.GetButtonDown(Joycon.Button.SHOULDER_2))
         * {
         *  m_joyconR.Recenter();
         * }*/
    }
        private void SetRotation()
        {
            Vector3 orientation = ActionInput.GetJoyconVector();
            Vector3 angles      = transform.localEulerAngles;

            angles.z = orientation.y + 180;

            transform.localEulerAngles = angles;
        }
    protected override void Update()
    {
        base.Update();

        transform.rotation   = Quaternion.Euler(new Vector3(0, 0, ActionInput.GetJoyconVector().y + startAngle));
        transform.localScale = ActionInput.GetJoyconAccel();
        Vector3 tmpS = transform.localScale;

        /*
         * tmpS.x = Mathf.Max(tmpS.x, 0.5f);
         * tmpS.y = Mathf.Max(tmpS.y, 0.5f);
         * tmpS.z = Mathf.Max(tmpS.z, 0.5f);
         * transform.localScale = tmpS;
         */
    }
Exemplo n.º 6
0
    protected override void Update()
    {
        base.Update();

        rb.MoveRotation(ActionInput.GetJoyconVector().y + startAngle);
    }
Exemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);

        if (ActionInput.GetButton(ButtonCode.RightArrow) && !isSquat)
        {
            power.x += accelVx * Time.deltaTime * 60;
            if (power.x > maxVx)
            {
                power.x -= accelVx * Time.deltaTime * 60;
                power.x  = Mathf.Max(power.x, maxVx);
            }
            else
            {
                power.x = Mathf.Min(power.x, maxVx);
            }
            direction = 1;
        }
        else if (ActionInput.GetButton(ButtonCode.LeftArrow) && !isSquat)
        {
            power.x -= accelVx * Time.deltaTime * 60;
            if (power.x < -maxVx)
            {
                power.x += accelVx * Time.deltaTime * 60;
                power.x  = Mathf.Min(power.x, -maxVx);
            }
            else
            {
                power.x = Mathf.Max(power.x, -maxVx);
            }
            direction = -1;
        }
        else
        {
            if (isGround)
            {
                if (power.x > 0)
                {
                    power.x -= accelVx * 2 * Time.deltaTime * 60;
                    power.x  = Mathf.Max(0, power.x);
                }
                else if (power.x < 0)
                {
                    power.x += accelVx * 2 * Time.deltaTime * 60;
                    power.x  = Mathf.Min(0, power.x);
                }
            }
            else
            {
                //スピードが早すぎるときは減速しない
                if (Mathf.Abs(power.x) < maxVx * 2)
                {
                    if (power.x > 0)
                    {
                        power.x -= accelVx * Time.deltaTime * 60;
                        power.x  = Mathf.Max(0, power.x);
                    }
                    else if (power.x < 0)
                    {
                        power.x += accelVx * Time.deltaTime * 60;
                        power.x  = Mathf.Min(0, power.x);
                    }
                }
            }
        }

        //スピードが早いときは減速しない
        if (Mathf.Abs(power.x) < maxVx)
        {
            if (power.x > maxVx)
            {
                power.x -= accelVx * Time.deltaTime * 60;
                power.x  = Mathf.Max(power.x, maxVx);
            }
            else if (power.x < -maxVx)
            {
                power.x += accelVx * Time.deltaTime * 60;
                power.x  = Mathf.Min(power.x, -maxVx);
            }
        }

        //風
        if (wind != null)
        {
            //power.x += -Mathf.Cos((ActionInput.GetJoyconVector().y + 90) * Mathf.Deg2Rad) * 00.5f;
            gravity = defaultGravity - Mathf.Sin((ActionInput.GetJoyconVector().y + 90) * Mathf.Deg2Rad) * 0.02f;
        }



        transform.localScale = new Vector3(
            defaultScaleX * direction, transform.localScale.y, transform.localScale.x);

        isSquat = stateInfo.IsName("squat");

        if (ActionInput.GetButton(ButtonCode.DownArrow))
        {
            animator.SetBool("squat", true);
        }
        else
        {
            animator.SetBool("squat", false);
        }

        if (isContactRight)
        {
            power.x = Mathf.Min(power.x, 0);
        }

        if (isContactLeft)
        {
            power.x = Mathf.Max(power.x, 0);
        }

        if (ActionInput.GetButtonDown(ButtonCode.Jump) && jumpEnabled)
        {
            if (!isGround)
            {
                airJumpTimes--;
                if (airJumpTimes <= 0)
                {
                    jumpEnabled = false;
                }
            }
            isJumping  = true;
            jumpFrames = defaultJumpFrames;
            power.y    = maxVy;
            isGround   = false;
            animator.SetBool("Jump", true); // tada
            //音
            audioSource.PlayOneShot(jumpSE);
            //エフェクト
            JumpEffFire();
        }

        if (isGround)
        {
            airJumpTimes = defaultAirJumpTimes;
            jumpEnabled  = true;
            jumpCooltime = jumpDefaultCooltime;
            isJumping    = false;
            jumpFrames   = defaultJumpFrames;
            power.y      = 0;
            animator.SetBool("Jump", false); // tada
            if (power.magnitude < 0.01f)
            {
                v = Vector2.zero;
            }
            v = Vector3.ProjectOnPlane(power, groundNormal);
            //風
            if (wind != null)
            {
                v.x += -Mathf.Cos((ActionInput.GetJoyconVector().y + 90) * Mathf.Deg2Rad) * 0.1f;
            }
            v.x = Mathf.Clamp(v.x, -maxVx * 2, maxVx * 2);
            Debug.DrawRay(groundPoint, groundNormal, Color.red);
            //Debug.DrawRay(groundPoint, v, Color.red);
        }
        else
        {
            //ジャンプ
            if (jumpCooltime > 0)
            {
                jumpCooltime -= Time.deltaTime;
            }
            else
            {
                if (airJumpTimes == 0)
                {
                    jumpEnabled = false;
                }
            }

            if (isJumping && jumpFrames > 0)
            {
                if (ActionInput.GetButtonDown(ButtonCode.Jump))
                {
                    animator.Play("PlayerJump", 0, 0.0f); // tada
                    //音
                    audioSource.PlayOneShot(jumpSE);
                }
                if (ActionInput.GetButton(ButtonCode.Jump))
                {
                    jumpFrames -= Time.deltaTime;
                    power.y     = maxVy;
                    isGround    = false;
                }
                else
                {
                    isJumping = false;
                }
            }
            else
            {
                power.y += gravity * Time.deltaTime * 60;
            }
            power.y = Mathf.Clamp(power.y, -maxVy, maxVy * 2);
            v       = power;
            //風
            if (wind != null)
            {
                v.x += -Mathf.Cos((ActionInput.GetJoyconVector().y + 90) * Mathf.Deg2Rad) * 0.25f;
            }
            v.x = Mathf.Clamp(v.x, -maxVx * 2, maxVx * 2);
        }

        isMoving = Mathf.Abs(power.x) > 0;

        //エフェクト
        if ((isGround && !oldIsGround) || (isGround && !asikemuri.isPlaying && isMoving))
        {
            asikemuri.Play();
        }

        if ((!isGround && oldIsGround) || (isGround && asikemuri.isPlaying && !isMoving))
        {
            asikemuri.Stop();
        }

        if (isGround && !oldIsGround)
        {
            LaundEffFire();
        }

        if (isGround && v.magnitude > 0)
        {
            //audioSource.clip = ashiSE;
            //audioSource.Play();
        }
        else
        {
            //audioSource.clip = null;
            //audioSource.Stop();
        }

        //地面に付いてるか保存
        oldIsGround = isGround;
        oldIsMoving = isMoving;

        //rb.velocity = v + rv;
        rb.MovePosition(transform.position + (Vector3)v * Time.deltaTime * 60);
        //rv = Vector2.zero;
        //rv = Vector2.zero;
        //transform.position += (Vector3)v;
        Debug.DrawRay(transform.position, v * Time.deltaTime * 60, Color.white);
        //Debug.Log("速さ:"+v.magnitude);

        // tada
        animator.SetFloat("MoveSpeed", Mathf.Abs(v.x));
    }