Hello, recently I’ve been trying to achieve 3D GUI. However, I got stuck on an issue when it flips at certain angle. What I think is causing this issue is that it’s going from 355-360 degrees to 0 degrees.
Video of how it should be everywhere:
As you can see in this video, its working as expected. However, in the next video…
…It doesn’t. At this and only this angle it just… flips.
Rotation source code:
local oldRot = nil
game:GetService("RunService").RenderStepped:Connect(function()
local cameraAngularVelocity = Vector3.new()
if oldRot then
cameraAngularVelocity = velAttachment.WorldOrientation - oldRot
end
velAttachment.Orientation = velAttachment.Orientation:Lerp(Vector3.new(-2.5 - cameraAngularVelocity.X, cameraAngularVelocity.Y*-1, 0), 0.1)
uiPart.CFrame = uiPart.CFrame:Lerp(velAttachment.WorldCFrame, 0.1)
oldRot = velAttachment.WorldOrientation
end)
You might want to find a way to use CFrames on the velAttachment lerp too, vector3 lerping is way more simplistic than cframe lerping (which uses fancy quaternions which should hopefully prevent this issue)
I almost forgot about how it all works but I’ll try my best to explain it. There are like 3 physical parts:
a parent part - positioned at the camera’s CFrame but offset to be in front
an attachment - used for position offset and rotation
the part that the UI is displayed on - set to be at the attachment’s position and orientation
The attachment’s orientation is controlled by the character’s angular velocity and is running on RenderStepped event. If all you want is a small rotation effect, then you can stop there
However, if you want to have some position effects, you can click here
When you offset the UI to be farther away it makes itself smaller, you will have to adjust for that. There’s like code samples online that you can search for if you want to do it through scripting
The attachment’s offset (controlled by the Position property) is affected by character’s velocity and clamped to make sure it doesn’t clip through the camera or stray too far away
And all of this is run every frame so you can do all this in a function or in multiple functions and connect them to a RenderStepped event
If you want for me to go more in depth, feel free to DM me