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 ))