Пример #1
0
    void FixedUpdate()
    {
        // プレイヤー位置の地面の法線の更新
        surfaceNormal = transform.position - Vector3.zero;
        surfaceNormal = surfaceNormal.normalized;


        /// 移動処理
        ///

        // カメラ進行方向ベクトルを取得
        if (isLocalPlayer)
        {
            Vector3 cameraForward = Vector3.Scale(cam.transform.forward, new Vector3(1, 1, 1)).normalized;
            Vector3 moveForward;

            // 方向キーの入力値とカメラの向きから、移動方向を決定
            //moveForward = cameraForward * inputVertical + Camera.main.transform.right * inputHorizontal;
            moveForward = cameraForward * inputVec.y + cam.transform.right * inputVec.x;

            // 移動方向にスピードを掛ける
            moveVec = moveForward * 0.05f;

            moveVec             = Vector3.ProjectOnPlane(moveForward, surfaceNormal) * 0.05f;
            moveVec            += (Vector3.zero - moveVec) * 0.5f;
            transform.position += moveVec;

            if (moveVec.magnitude > 0)
            {
                dirVec = moveVec.normalized;
            }

            // プレイヤーの回転
            transform.rotation = Quaternion.LookRotation(dirVec, surfaceNormal);

            // アニメーション状態取得
            if (moveVec.magnitude > 0)
            {
                animator.SetBool("is_running", true);
                particleManager.SetSmokeFlg(true);
            }
            else
            {
                animator.SetBool("is_running", false);
                particleManager.SetSmokeFlg(false);
            }

            // 球面中心点からプレイヤーまでの距離更新
            radPlayer = Mathf.Sqrt(
                transform.position.x * transform.position.x
                + transform.position.y * transform.position.y
                + transform.position.z * transform.position.z);

            // プレイヤー位置差分の取得
            difPosition = transform.position - prePosition;

            prePosition = transform.position;
        }
    }
    void FixedUpdate()
    {
        // プレイヤー位置の地面の法線の更新
        surfaceNormal = transform.position - Vector3.zero;
        surfaceNormal = surfaceNormal.normalized;


        /// 移動処理

        // カメラ進行方向ベクトルを取得
        //Vector3 cameraForward = Vector3.Scale(camera.transform.forward, new Vector3(1, 1, 1)).normalized;
        Vector3 cameraForward = Vector3.Scale(cameraStand.GetCameraDirection, new Vector3(1, 1, 1)).normalized;
        Vector3 moveForward;

        // 方向キーの入力値とカメラの向きから、移動方向を決定
        //moveForward = cameraForward * inputVertical + Camera.main.transform.right * inputHorizontal;
        moveForward = cameraForward * inputVecN.y + cam.transform.right * inputVecN.x;

        // 入力量によって移動速度を変える

        if (VecLength < moveDead)
        {
            move         = false;
            animationNum = AnimationNum.Idle;
        }
        else
        {
            move = true;
        }


        if (move)
        {
            if (VecLength < (puniVecMax * moveThre))
            {
                moveVec      = Vector3.ProjectOnPlane(moveForward, surfaceNormal) * moveWalkSpeed;
                animationNum = AnimationNum.Walk;
            }
            else if (VecLength >= (puniVecMax * moveThre))
            {
                moveVec      = Vector3.ProjectOnPlane(moveForward, surfaceNormal) * moveRunSpeed;
                animationNum = AnimationNum.Running;
            }
        }
        else
        {
            moveVec      = Vector3.ProjectOnPlane(moveForward, surfaceNormal) * moveWalkSpeed;
            animationNum = AnimationNum.Idle;
        }


        // 慣性
        moveVec += (Vector3.zero - moveVec) * moveIn;

        // 移動速度を位置に足しこむ
        if (move)
        {
            transform.position += moveVec;
        }

        if (moveVec.magnitude > 0)
        {
            dirVec = moveVec.normalized;
        }

        // プレイヤーの回転
        if (move || (deadTrans && (VecLength > moveDeadMin)))
        {
            transform.rotation = Quaternion.LookRotation(dirVec, surfaceNormal);
        }
        // アニメーション状態取得
        if (moveVec.magnitude > 0)
        {
            move = true;
        }
        else
        {
            move = false;
        }

        /// アニメーション状態によって動作を変える
        ///
        switch (animationNum)
        {
        case AnimationNum.Idle:
        {
            animator.SetBool("is_action", false);
            animator.SetBool("is_walk", false);
            animator.SetBool("is_running", false);
            particleManager.SetSmokeFlg(false);

            seCnt = 0;
            break;
        }

        case AnimationNum.Walk:
        {
            animator.SetBool("is_walk", true);
            animator.SetBool("is_running", false);
            particleManager.SetSmokeFlg(false);

            footStampTime += Time.deltaTime;

            if (footStampTime > footStampSetTime)
            {
                footStampTime = 0;
                Instantiate(footStampPrefab, transform.position, transform.rotation);
            }

            if (seCnt == 20)
            {
                audioManager.Play_SE(AudioManager.SE.Run);
                seCnt = 0;
            }
            else
            {
                seCnt++;
            }
            break;
        }

        case AnimationNum.Running:
        {
            animator.SetBool("is_running", true);
            //animator.SetBool("is_walk", false);
            particleManager.SetSmokeFlg(true);

            footStampTime += Time.deltaTime;

            if (footStampTime > footStampSetTime)
            {
                footStampTime = 0;
                Instantiate(footStampPrefab, transform.position, transform.rotation);
            }

            if (seCnt == 15)
            {
                audioManager.Play_SE(AudioManager.SE.Run);
                seCnt = 0;
            }
            else
            {
                seCnt++;
            }
            break;
        }
        }



        // 球面中心点からプレイヤーまでの距離更新]
        radPlayer = Mathf.Sqrt(
            transform.position.x * transform.position.x
            + transform.position.y * transform.position.y
            + transform.position.z * transform.position.z);

        // プレイヤー位置差分の取得
        difPosition = transform.position - prePosition;

        prePosition = transform.position;
    }