2017-05-10 40 views
0

我正在使用A-Frame編寫WebVR應用程序。該應用程序大多爲Cardboard用戶量身定做。在桌面上,只需將wasd-controls組件添加到相機中即可使用WASD進行移動。但是,我希望能夠以相同的方式移動,而不是使用紙板按鈕(即屏幕觸摸),而方向取決於相機的方向。有沒有一個簡單的方法來做到這一點與A幀?如何使用Google Cardboard的按鈕使用A框移動?

+0

也許這[post](http://stackoverflow.com/a/43403936/6940428)會有所幫助。 –

回答

2

正如您所指出的,wasd-controls實際上只是設計用於桌面鍵盤控制。我寫了一個可比較的universal-controls component,它可以選擇性地替換look-controlswasd-controls。有了這個組件,按下按鈕,紙板將在方向移動攝像機,它正面臨着:

<a-entity camera universal-controls></a-entity> 

或者,您可以定義「闖關」,當使用者注視他們,瞬移相機。在許多情況下,這可能會帶來更好的用戶體驗。 Demosource

<!-- Player --> 
    <a-entity camera="userHeight: 1.6" 
      universal-controls="movementControls: checkpoint" 
      checkpoint-controls="mode: teleport"> 
    <a-entity cursor 
       position="0 0 -1" 
       geometry="primitive: ring; radiusInner: 0.02; radiusOuter: 0.03;" 
       material="color: #CCC; shader: flat;"> 
    </a-entity> 
    </a-entity> 

    <!-- Terrain --> 
    <a-grid></a-grid> 

    <!-- Checkpoints --> 
    <a-entity position="1 0 1"> 
    <a-cylinder checkpoint="offset: 0 1.6 0" radius="1" height="0.1" position="0 0 -5.2" color="#39BB82"></a-cylinder> 
    <a-cylinder checkpoint="offset: 0 1.6 0" radius="1" height="0.1" position="3 0 0" color="#39BB82"></a-cylinder> 
    <a-cylinder checkpoint="offset: 0 1.6 0" radius="1" height="0.1" position="-3 0 0" color="#39BB82"></a-cylinder> 
    </a-entity> 

這些選項都在aframe-extras package,增加了若干組件A字架來實現。

+0

這絕對是太棒了 - 正是我所需要的,甚至沒有寫一行Javascript。非常感謝!! – singwukgwu

相關問題