I’m trying to make a game where you experience how it’s like using a VR Headset (Oculus Quest 2 in this case).
I know the UI and such since I own one, incase you’re wondering about the difficulty of remaking something like this.
I need one thing to know if it’s possible, with an example of how it would look like.
When locked into first-person in the game, there’s a part with a SurfaceGUI following you around your head whenever you pan it left or right.
Example:
Is something like this possible where the UI follows your head depending on the direction you’re facing?
I’ve tried to look into the Nexus VR Source Code and could not find anything as an example.
A demo file would be appreciated, I know that it would include a lot of CFraming and Tweening.
Wouldn’t all this be a lot of CFraming and Tweening?
Since It’s just a Part floating in front of your head and following you as you look into different directions…
I think the easiest way to do this will be using roblox’s physics engine with AlignPosition and a Surface Gui
I’ve attached a very simple place with a surface gui in replicated storage and one local script in starter character scripts to get this working. quest_ui.rbxl (38.0 KB)
here is the script but the greater context is in the parts
--!strict
local character: Model = script.Parent
local hudpart = Instance.new("Part")
hudpart.Position = Vector3.new(0, 6, -6)
hudpart.CanCollide = false
hudpart.CanTouch = false
hudpart.Parent = character:FindFirstChild("Head")
local weld = Instance.new("WeldConstraint")
weld.Part1 = hudpart
weld.Part0 = character:FindFirstChild("Head") :: Part
weld.Parent = hudpart
local hudAttachment = Instance.new("Attachment", hudpart)
local hud = game.ReplicatedStorage.hud:Clone()
hud.AlignPosition.Attachment1 = hudAttachment
hud.AlignOrientation.Attachment1 = hudAttachment
hud.Parent = character
use a part to get the orientation of the camera (by setting the part’s cframe to the camera cframe) then have it constantly compare the rotation of the ui and your camera, and if it is too great, rotate the ui to match the camera orientation.
you can also calculate the position using math.sin() and math.cos(). Just put the ui at (math.cos(cameraRotationAngle), height, math.sin(cameraRotationAngle)) + rotation center
It is probably not an R6 issue, my original solution has that bug, if your player spawns far away from the world origin then the UI will be far away from them. If they spawn slightly away the UI will look slightly off. Use the updated code for your published game.
It shouldn’t matter what body type they have as long as you can weld the hudpart onto something that rotates with them, Torso would work, maybe even better.