In this example, we will move a camera with comments using VCI.
Receive comments with vci.message(receive comments), detect the content of comments, and use vci.studio(ExportStudio)&(ExportSystemItem) to move the camera.
This VCI doesn't require any SubItems.
local _commentControllerIsActive = true -- When true, it can be controlled with comments local _Maxheight = 3.0 --The maximum height it can be moved to using comments local _Minheight = 0.3 --The minimum height it can be moved to using comments function onUse(use) -- Enable/Disable the VCI on use --[[ if use == "Board" then _commentControllerIsActive = not(_commentControllerIsActive) print("Controller : "..tostring(_commentControllerIsActive)) end ]] end -- Change the position of the camera function setCommentPosition(pos) if _commentControllerIsActive == false then print("Camera control with comments is disabled") return end if vci.studio.HasHandiCamera() == false then print("Handy camera doesn't exist. End.") return end local cam = vci.studio.GetHandiCamera() if (pos.y < 0.01) and (cam.GetPosition().y < _Minheight) then print("The camera cannot be controlled with comments as it's in the minimum height") pos.y = 0 -- ignore by changing y to 0 end if (pos.y > 0.01) and (cam.GetPosition().y > _Maxheight) then print("The camera cannot be controlled with comments as it's in the maximum height") pos.y = 0 -- ignore by changing y to 0 end pos = cam.GetRotation() * pos pos = pos + cam.GetPosition() cam.SetPosition(pos) --print("Cam Position : "..tostring(cam.GetPosition())) end -- Change the rotation of the camera function setCommentRotation(rot) if _commentControllerIsActive == false then print("Camera controll with comments is disabled") return end if vci.studio.HasHandiCamera() == false then print("Handy camera doesn't exist. End.") return end local cam = vci.studio.GetHandiCamera() rot = cam.GetRotation() * rot cam.SetRotation(rot) --print("Cam Position : "..tostring(cam.GetPosition())) end -- Processes on comment receiption function onMessage(sender, name, message) -- Content of the comment print(sender["name"].."「"..message.."」") -- The position and rotation to be added with comments local pos = Vector3.zero local rot = Quaternion.identity -- You can change the distance to move with a single comment. In meter. local movingDistance = 0.2 -- You can change the angle to rotate with a single comment. In degree. local rotationAngle = 10 -- Forward if string.find(message,"Forward") ~= nil or string.find(message,"forward") ~= nil then pos.z = pos.z + movingDistance end -- Backward if string.find(message,"Back") ~= nil or string.find(message,"back") ~= nil then pos.z = pos.z - movingDistance end -- Upward if string.find(message,"Up") ~= nil or string.find(message,"up") ~= nil then pos.y = pos.y + movingDistance end -- Down if string.find(message,"Down") ~= nil or string.find(message,"down") ~= nil then pos.y = pos.y - movingDistance end -- The comment includes right if string.find(message,"Right") ~= nil or string.find(message,"right") ~= nil then -- When the comment contains "Turn," process rotation and end if string.find(message,"Turn") ~= nil or string.find(message,"turn") ~= nil then rot = Quaternion.AngleAxis(rotationAngle, Vector3.up) setCommentRotation(rot) return end -- Move right pos.x = movingDistance end -- The comment includes left if string.find(message,"Left") ~= nil or string.find(message,"left") ~= nil then -- When the comment contains "Turn," process rotation and end if string.find(message,"Turn") ~= nil or string.find(message,"turn") ~= nil then rot = Quaternion.AngleAxis(-rotationAngle, Vector3.up) setCommentRotation(rot) return end --Move left pos.x = -movingDistance end -- Update the position setCommentPosition(pos) end -- Receiving comments vci.message.On('comment', onMessage)
You can create a camera collider by creating a SubItem that follows the position of the camera. You can push the camera away by adding a process that moves the camera away when touched.