Quest-like UI Movement Behavior

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.

Using viewport frames may be the best way to go about this. The website below can help you learn how to use them if you need the help.

https://developer.roblox.com/en-us/articles/viewportframe-gui

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 guess so then yes. Sorry I thought it was a ScreenGui

Oh nono, it’s alright.
It’s a part with a SurfaceGui on it. All I need to know is if it’s possible to do something like that like in the video shown

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
2 Likes

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

Exactly what I needed, thank you.

Is there a way I can change the height of the HUD Part?

image

If so, which one do I change?

(x, y, z)
Y the positive 6 is height
Z the negative 6 is how far away from the player (-10 would be farther away)

X would be left/right offset

1 Like

change the second value, it goes x,y,z and y is up and down

1 Like

Perfect, thank you again :sunglasses:

30chaxracters

this seems to work only if the head starts at 0,height,0 though, otherwise it may weld weirdly

1 Like
--!strict
local character: Model = script.Parent
local characterHead = character:FindFirstChild("Head") :: Part

local hudpart = Instance.new("Part")
hudpart.Position = Vector3.new(0, 0, -6) + characterHead.Position
hudpart.CanCollide = false
hudpart.CanTouch = false
hudpart.Parent = characterHead

local weld = Instance.new("WeldConstraint")
weld.Part1 = hudpart
weld.Part0 = characterHead
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

Here is a updated script to solve that problem

1 Like

image
It looks a bit to the side

This is also fixed in the updated script I posted, which should always align to the player’s head before welding.

1 Like

I’ve made the game R6 since it follows the head movement, which will cause issues because of animations.

It may be an R6 problem… no?

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.

1 Like

Stupid me, there’s no issue.

I always ran in “Play here” and not in the original world position.

Everything works perfectly as needed, thank you for this :sunglasses:

Sorry for the accidental wrong emoji… lol

that can be fixed using look vectors