~~NOTOC~~ ====== ExportRoomPlayer/Controller(プレイヤー情報と物理制御) ====== このページは過去の情報となります。\\ 新しいスクリプトリファレンスは**[[https://developer.virtualcast.jp/vci-docs/api/|こちら]]**になります。 プレイヤー情報を取得、物理演算の制御を行うクラスです。 * **UniVCI v0.35** 以降で Export される VCI で使用できます。 * **バーチャルキャスト v2.3.0** 以降で動作します。 * 現在、この API は**ルーム上でのみ動作します**。 ===== メンバ変数・関数一覧 ===== ^ ExportRoomPlayer ^^ ^ 名前 ^ 説明 ^ | [[vci/script/reference/exportroomplayer#IsAvailable ]] | プレイヤーがルームに存在するか | | [[vci/script/reference/exportroomplayer#GetId ]] | プレイヤーのIDを取得 | | [[vci/script/reference/exportroomplayer#GetName ]] | プレイヤーの名前を取得 | | [[vci/script/reference/exportroomplayer#GetUserType ]] | プレイヤーのアカウント種別を取得 | | [[vci/script/reference/exportroomplayer#GetIsLocal ]] | ローカルのプレイヤーがどうかを取得 | | [[vci/script/reference/exportroomplayer#GetPosition ]] | プレイヤーの足元に相当する位置を取得 | | [[vci/script/reference/exportroomplayer#GetRotation ]] | プレイヤーの頭のY軸回転に相当する回転を取得 | | [[vci/script/reference/exportroomplayer#GetForward ]] | プレイヤーの前方を指す正規化ベクトルを取得 | | [[vci/script/reference/exportroomplayer#GetUp ]] | プレイヤーの上方を指す正規化ベクトルを取得 | | [[vci/script/reference/exportroomplayer#GetRight ]] | プレイヤーの右方を指す正規化ベクトルを取得 | | [[vci/script/reference/exportroomplayer#GetRoomPlayerController ]] | プレイヤーに対する操作を提供するオブジェクトを取得 | | [[vci/script/reference/exportroomplayer#Character ]] | プレイヤーが使用しているキャラクター(アバター)の情報を取得 | ^ ExportRoomPlayerController ^^ ^ 名前 ^ 説明 ^ | [[vci/script/reference/exportroomplayer#IsGrounded ]] | プレイヤーRigidbodyが接地しているか | | [[vci/script/reference/exportroomplayer#GetVelocity ]] | プレイヤーRigidbodyの速度 | | [[vci/script/reference/exportroomplayer#GetMass ]] | プレイヤーRigidbodyの質量 | | [[vci/script/reference/exportroomplayer#SetVelocity ]] | プレイヤーRigidbodyの速度を設定する | | [[vci/script/reference/exportroomplayer#TeleportTo ]] | プレイヤーRigidbodyのワールド位置、ワールド角度を指定して移動する | | [[vci/script/reference/exportroomplayer#AddForce ]] | プレイヤーRigidbodyに力を与える | ===== IsAvailable ===== ExportRoomPlayer.**IsAvailable fun(): bool**\\ プレイヤーがルームに存在するか。\\ 存在しない場合は false を返す。 ===== GetId ===== ExportRoomPlayer.**GetId fun(): string**\\ プレイヤーのIDを取得する。\\ フォーマットは最大16文字の16進数文字列 (e.g. ''"4b32da78cc0a9213"'') === サンプル === local player = vci.vc.room.GetLocalPlayer() -- プレイヤー情報の取得 print("ID: "..player.GetId()) ===== GetName ===== ExportRoomPlayer.**GetName fun(): string**\\ プレイヤーの名前を取得する。 === サンプル === local player = vci.vc.room.GetLocalPlayer() -- プレイヤー情報の取得 print("Name: "..player.GetName()) ===== GetUserType ===== ExportRoomPlayer.**GetUserType fun(): string**\\ プレイヤーのアカウント種別を取得する。 === 返り値 === ^TSO| アカウントを連携しているプレイヤー| ^Anonymous| アカウント連携をしていないプレイヤー| === サンプル === local player = vci.vc.room.GetLocalPlayer() -- プレイヤー情報の取得 print("UserType: "..player.GetUserType()) -- "TSO" or "Anonymous" ===== GetIsLocal ===== ExportRoomPlayer.**GetIsLocal fun(): boolean**\\ ローカルのプレイヤーがどうかを取得する。 ===== GetPosition ===== ExportRoomPlayer.**GetPosition fun(): Vector3**\\ プレイヤーの足元に相当する位置を取得する。\\ ※リモートプレイヤーかつ ''Character.IsAvailable()'' が false の場合は nil が返されます。\\ ※実装の都合上、数フレーム前の時点の値が返ります。 === サンプル === local player = vci.vc.room.GetLocalPlayer() -- プレイヤー情報の取得 print("Position: "..tostring(player.GetPosition())) ===== GetRotation ===== ExportRoomPlayer.**GetRotation fun(): Quaternion**\\ プレイヤーの頭のY軸回転に相当する回転を取得する。\\ ※リモートプレイヤーかつ ''Character.IsAvailable()'' が false の場合は nil が返されます。\\ ※実装の都合上、数フレーム前の時点の値が返ります。 === サンプル === local player = vci.vc.room.GetLocalPlayer() -- プレイヤー情報の取得 print("Rotation: "..tostring(player.GetRotation())) ===== GetForward ===== ExportRoomPlayer.**GetForward fun(): Vector3**\\ プレイヤーの前方を指す正規化ベクトルを取得する。\\ ※リモートプレイヤーかつ ''Character.IsAvailable()'' が false の場合は nil が返されます。\\ ※実装の都合上、数フレーム前の時点の値が返ります。 ※ページ下のサンプルを参照のこと。 ===== GetUp ===== ExportRoomPlayer.**GetUp fun(): Vector3**\\ プレイヤーの上方を指す正規化ベクトルを取得する。\\ ※リモートプレイヤーかつ ''Character.IsAvailable()'' が false の場合は nil が返されます。\\ ※実装の都合上、数フレーム前の時点の値が返ります。 ※ページ下のサンプルを参照のこと。 ===== GetRight ===== ExportRoomPlayer.**GetRight fun(): Vector3**\\ プレイヤーの右方を指す正規化ベクトルを取得する。\\ ※リモートプレイヤーかつ ''Character.IsAvailable()'' が false の場合は nil が返されます。\\ ※実装の都合上、数フレーム前の時点の値が返ります。 ※ページ下のサンプルを参照のこと。 ===== GetRoomPlayerController ===== ExportRoomPlayer.**GetRoomPlayerController fun(): ExportRoomPlayerController**\\ プレイヤーに対する操作を提供するオブジェクトを取得する。\\ ※ローカルプレイヤーに対してのみ取得可能。\\ ※ローカルプレイヤーでない場合は nil を返します。 === サンプル === -- 物理演算制御クラスの取得 local playerController = player.GetRoomPlayerController() -- ローカルプレイヤー以外では nil が返る ===== Character ===== ExportRoomPlayer.**Character [[https://developer.virtualcast.jp/vci-docs/api/classes/ExportCharacter/index.html|ExportCharacter]]**\\ プレイヤーが使用しているキャラクター(アバター)の情報を取得する。\\ === サンプル === -- キャラクターモデル情報の取得 local character = player.Character ===== IsGrounded ===== ExportRoomPlayerController.**IsGrounded fun(): boolean**\\ プレイヤーRigidbodyが接地しているか。\\ ※実装の都合上、数フレーム前の時点の値が返ります。 === サンプル === local playerController = localPlayer.GetRoomPlayerController() -- ローカルプレイヤー以外では nil が返る -- 物理演算情報の取得 print("IsGrounded: "..tostring(playerController.IsGrounded())) ===== GetVelocity ===== ExportRoomPlayerController.**GetVelocity fun(): Vector3**\\ プレイヤーRigidbodyの速度 [m/s] を取得する。\\ ※実装の都合上、数フレーム前の時点の値が返ります。 === サンプル === local playerController = localPlayer.GetRoomPlayerController() -- ローカルプレイヤー以外では nil が返る -- 物理演算情報の取得 print("Velocity: "..tostring(playerController.GetVelocity())) ===== GetMass ===== ExportRoomPlayerController.**GetMass fun(): float**\\ プレイヤーRigidbodyの質量[kg]を取得する。\\ ※実装の都合上、数フレーム前の時点の値が返ります。 === サンプル === local playerController = localPlayer.GetRoomPlayerController() -- ローカルプレイヤー以外では nil が返る -- 物理演算情報の取得 print("Mass: "..playerController.GetMass()) ===== SetVelocity ===== ExportRoomPlayerController.**SetVelocity fun(velocity: Vector3)**\\ プレイヤーRigidbodyの速度 [m/s] を設定する。 ※ページ下のサンプルを参照のこと。 ===== TeleportTo ===== ExportRoomPlayerController.**TeleportTo fun(position: Vector3, rotation: Quaternion)**\\ プレイヤーRigidbodyのワールド位置、ワールド角度を指定して移動する。\\ rotationはY軸回転成分のみ反映される。 ※ページ下のサンプルを参照のこと。 ===== AddForce ===== ExportRoomPlayerController.**AddForce fun(force: Vector3, forceMode: ExportForce)**\\ プレイヤーRigidbodyに力を与える。 === 引数 === ^ forceMode: vci.forceMode.Force | force[N] の力を継続的に与える| ^ forceMode: vci.forceMode.Impulse | force[Ns] の力積を瞬発的に与える| === サンプル === local localPlayer = vci.vc.room.GetLocalPlayer() local playerController = localPlayer.GetRoomPlayerController() -- ローカルプレイヤー以外では nil が返る -- 物理演算情報の取得 print("IsGrounded: "..tostring(playerController.IsGrounded())) print("Velocity: "..tostring(playerController.GetVelocity())) print("Mass: "..playerController.GetMass()) -- キー入力に応じてプレイヤーを動かす local function moveHorizontallyByKeyboard(axis) if axis==Vector3.zero then return end -- 移動量 local speed = 10 --[m/s?] local deltaAngle = 10 --[degree] -- axis.xz で水平方向に初速度を与えて動かす local direction = localPlayer.GetRight() * axis.x direction = direction + localPlayer.GetForward() * axis.z if direction ~= Vector3.zero then playerController.SetVelocity(direction * speed) end -- axis.y で回転を与えて現在の座標と同位置にテレポート if axis.y ~= 0 then local position = localPlayer.GetPosition() local rotation = localPlayer.GetRotation() rotation = Quaternion.Euler(0, deltaAngle * axis.y, 0) * rotation playerController.TeleportTo(position, rotation) end print(tostring(localPlayer.GetPosition()) .. "," ..tostring(localPlayer.GetRotation())) end -- 鉛直上方向に力を与える local function addJumpForceToPlayerByKeyboard(button) if not button then return end local impulse = 10 --[Ns] local mass = playerController.GetMass() local force = impulse * mass print("[AddForce] IsGrounded: "..tostring(playerController.IsGrounded())) playerController.AddForce(Vector3.up * force, vci.forceMode.Impulse) end -- 鉛直上方向の初速度を与える local function addJumpVelocityToPlayerByKeyboard(button) if not button then return end local speed = 10 -- [m/s] print("[SetVelocity] IsGrounded: "..tostring(playerController.IsGrounded())) playerController.SetVelocity(Vector3.up * speed) end -- 原点に移動 local function teleportToOriginByKeyboard(button) if not button then return end playerController.TeleportTo(Vector3.zero, Quaternion.identity) print("reset position") end vci.StartCoroutine( coroutine.create( function() while true do -- GetAxisInput() -- →: x = +1, ←: x = -1 -- U: y = +1, I: y = -1 -- ↑: z = +1, ↓: z = -1 -- Acts like Unity GetKey -- GetButtonInput() -- Only 1, 2, 3, 4 key -- Acts like Unity GetKeyDown moveHorizontallyByKeyboard(vci.me.GetAxisInput()) addJumpForceToPlayerByKeyboard(vci.me.GetButtonInput(1)) addJumpVelocityToPlayerByKeyboard(vci.me.GetButtonInput(2)) teleportToOriginByKeyboard(vci.me.GetButtonInput(3)) coroutine.yield() end end ))