3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VCIのキーボード入力について

Posted at

はじめに

この記事ではバーチャルキャスト1.7.3aで追加された
vci.me.GetAxisInput()
vci.me.GetButtonInput()
について、キーボード入力の練習にポン出しボードを作った際に得られた情報を記載します。

キーの設定

バーチャルキャストの以下から設定します。
コントロール.png

API

vci.me.GetAxisInput()

Right,Left,Up,Down,Forward,Backwardのキー入力を検出する。
引数 : なし
返り値 : Vector3

キー入力と戻り値の一覧

キー 返り値
入力なし (0, 0, 0)
Right (1, 0, 0)
Left (-1, 0, 0)
Up (0, 1, 0)
Down (0, -1, 0)
Forward (0, 0, 1)
Backward (0, 0, -1)
 キーを押している間、押したキーに応じた値が取得できます。
 複数のキーを同時に押した場合、返り値は足し算した結果となります。
例)
 "Right"と"Up"を同時に押した場合、(1, 1, 0)が返ります。
 "Right"と"Left"を同時に押した場合、(0, 0, 0)が返り、キーが入力されていないのと同じ状態になります。

使用方法

---アイテムを生成したユーザーで毎フレーム呼ばれる
function update()
    local axis = vci.me.GetAxisInput()

    if axis.x == 1 then
        print("Right")
    end
    if axis.x == -1 then
        print("Left")
    end
    if axis.y == 1 then
        print("Up")
    end
    if axis.y == -1 then
        print("Down")
    end
    if axis.z == 1 then
        print("Forward")
    end
    if axis.z == -1 then
        print("Backward")
    end
end

備考

vci.me.GetAxisInput()はキーを押している間、押したキーに応じた値が返却されます。
そのため、キー入力に応じてなにか処理をする場合、グローバル変数で最後のキー入力を覚えておき、前回のキー入力と同じ場合なにもしない等の対応が必要です。
また、誤操作やチャタリング対策に、特定フレーム数や特定秒数同じキーが入力された場合、キーが入力されたと判定すると安全かもしれません。(ポン出しボードでは0.1秒間押しつづけた場合としていす)

vci.me.GetButtonInput()

指定されたボタンが押されているか判定する。
引数 : number(1-4)
返り値 : bool

状態 返り値
押されている true
押されていない false

使用方法

---アイテムを生成したユーザーで毎フレーム呼ばれる
function update()
    if vci.me.GetButtonInput(1) == true then
        print("ボタン1が押されました")
    end
    if vci.me.GetButtonInput(2) == true then
        print("ボタン2が押されました")
    end
    if vci.me.GetButtonInput(3) == true then
        print("ボタン3が押されました")
    end
    if vci.me.GetButtonInput(4) == true then
        print("ボタン4が押されました")
    end
end

備考

update()やupdateAll()でボタンが押されたことを検出する場合、ボタンが押された1フレームのみtrueが返却されます。

以上

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?