---
title: クォータービューの例
slug: world-sdk-guide-ja/M5DumLWhfaZHGMuw12Ii6
docTags: 
createdAt: 2024-09-02T08:34:13.135Z
---

ZEPETOキャラクターのコントロールは、V-Padの代わりにUnityの新しい入力システムを使用するようにカスタマイズできます。

これらはクォータービューコントロールの設定の例です。

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-xmQtwzWGSIx89Sk3SXoD--20240904-102421.gif)



## ステップ1：カメラビュー設定

カメラをクォータービューに設定します（これは例ですので、プロジェクトに応じてカメラ設定を変更してください）。

この時点で、カメラのタグはMainCameraに設定されている必要があります。

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-4LZZcBKXUC_vjjaBZ0NHG-20240904-102421.png)

## ステップ2：InputAction設定

クォータービューのために新しいInputActionを定義することで、タッチスクリーンを通じてキャラクターの動きを制御できます。

作成 > 入力アクションを選択し、ファイル名をQuarterViewActionsに設定します。

- 移動
  - アクションタイプ：パススルー
- 移動トリガー
  - アクションタイプ：ボタン

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-9m15KB6FImRIffLFOQJyO-20240904-102421.png)



階層 > 空のオブジェクトを作成した後、ファイル名をQuarterViewControllerに変更します。

QuarterViewControllerオブジェクトから、コンポーネントを追加を選択し、プレイヤー入力を追加します。

::Image[]{src="https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-hoF1gVUhEJKbPMIEVxZVV-20240904-102421.png" size="84" width="407" height="290" position="center" showCaption="false"}



作成したQuarterViewアクションをドラッグして、アクションリストに接続します。

動作をUnityイベントを呼び出すように変更します。

![](https://api.archbee.com/api/optimize/fCt3n1oCa8rgNJ8fw9I2N-RDg-RfMrNca4Ctr_HbZEg-20240904-102421.png)



## ステップ 3 : スクリプティング

タッチスクリーン入力を通じてキャラクターの動きの方向を計算するスクリプトを書いてください。

作成 > ZEPETO > TypeScriptを選択し、QuarterView Controllerに名前を変更します。

スクリプトをQuarterView Controllerオブジェクトに追加します。

```typescript
import {ZepetoScriptBehaviour} from 'ZEPETO.Script'
import {PlayerInput,InputAction} from "UnityEngine.InputSystem"
import {CallbackContext} from "UnityEngine.InputSystem.InputAction"
import {CharacterState, ZepetoCharacter, ZepetoPlayers, ZepetoCamera} from 'ZEPETO.Character.Controller'
import {Camera, Quaternion, Time, Vector2, Vector3, WaitForEndOfFrame} from "UnityEngine";

export default class QuarterViewController extends ZepetoScriptBehaviour {

    private myCharacter: ZepetoCharacter;
    private startPos: Vector2 = Vector2.zero;
    private curPos: Vector2 = Vector2.zero;

    private playerInput: PlayerInput;
    private touchPositionAction : InputAction;
    private touchTriggerAction : InputAction;

    private isTriggered: boolean = false;
    private isTouchDown: boolean = false;

    private CanMove() : boolean {
        return this.isTouchDown && !this.isTriggered;
    }


    OnEnable(){
        this.playerInput = this.gameObject.GetComponent<PlayerInput>();
    }

    Start() {

        this.touchTriggerAction = this.playerInput.actions.FindAction("MoveTrigger");
        this.touchPositionAction = this.playerInput.actions.FindAction("Move");

        this.touchTriggerAction.add_started((context)=>{
            this.isTriggered = true;
            this.isTouchDown = true;
        });

        this.touchTriggerAction.add_canceled((context)=>{
            this.isTriggered = false;
            this.isTouchDown = false;
        });

        this.touchPositionAction.add_performed((context)=>{
            
            if(this.isTouchDown)
            {
                this.curPos = context.ReadValueAsObject() as Vector2;

                if(this.isTriggered) {
                    this.isTriggered = false;
                    this.startPos = this.curPos;
                }
            }
        });


        ZepetoPlayers.instance.OnAddedLocalPlayer.AddListener(() => {
            ZepetoPlayers.instance.LocalPlayer.zepetoCamera.gameObject.SetActive(false);
            this.myCharacter = ZepetoPlayers.instance.LocalPlayer.zepetoPlayer.character;

            this.StartCoroutine(this.InputControlLoop());
        });
    }

    private *InputControlLoop(){
        while(true)
        {
            yield new WaitForEndOfFrame();

            if (this.myCharacter && this.CanMove()) {

                var camRot = Quaternion.Euler(0, Camera.main.transform.rotation.eulerAngles.y, 0);
                var moveDir = Vector2.op_Subtraction(this.curPos, this.startPos);
                moveDir = Vector2.op_Division(moveDir, 100);


                if (moveDir.magnitude > 0) {

                    if(moveDir.magnitude > 1)
                        moveDir.Normalize();

                    var optMoveDir = new Vector3(moveDir.x, 0, moveDir.y);
                    optMoveDir = Vector3.op_Multiply(optMoveDir, Time.deltaTime * 80 );
                    this.myCharacter.Move(camRot * optMoveDir);
                }
            }
        }
    }
}
```

