Appearance
AvatarPositionControllerクラス
a3.AvatarPositionControllerは、キーボードでアバター (キャラクター)を操作するコントローラーです。
- W/A/S/D — 前後左右に移動します。
- ←→ 矢印キー — 左右に回転します。
- Space — ジャンプします。
setPosition()で位置を指定する方式のため、接地判定が正確で 安定しているのが特徴です。 KinematicCharacterモードまたは DynamicCharacterモードのアバターと 組み合わせて使います。周囲の剛体を押したり押されたりする相互作用が 必要な場合は AvatarVelocityControllerクラスを 使ってください。
js
view.setController(new a3.AvatarPositionController(player));生成オプション
第2引数でオプションを指定できます。
speed— 移動速度(1フレームあたりの移動距離)。デフォルトは0.1。angSpeed— 回転速度(1フレームあたりのラジアン)。デフォルトは0.01。
サンプル
KinematicCharacterモードのロボットをW/A/S/Dキーで動かすサンプル です(キーが効かないときは一度3D表示部分をクリックしてください)。
js
import * as a3 from 'a3js';
await a3.initPhysics();
const view = new a3.Window(600,300);
const ground = await new a3.GLTF('/a3js/assets/grass-ground2.glb').ready;
ground.setMode('SimplePhysics',{meshCollider:'tri_mesh',rigidBody:'fixed'});
view.scene.add(ground);
const player = await new a3.GLTF('/a3js/assets/RobotExpressive.glb').ready;
player.setScale(0.5,0.5,0.5);
player.setMode('KinematicCharacter');
player.setState('Walking');
player.setPosition(0,2,0);
view.scene.add(player);
// W/A/S/Dで移動、←→で回転、Spaceでジャンプ
// (キーが効かないときは一度3D表示部分をクリック)
view.setController(new a3.AvatarPositionController(player));
view.camera.setMode('Follow',{target:player,lookFrom:{x:0,y:2,z:-4}});
// ぶつかると押せる箱(dynamic)
const box = new a3.Box('red');
box.setMode('SimplePhysics');
box.setPositionNow(0,1,3);
view.scene.add(box);詳細はAPIドキュメントを 参照してください。