[SOLVED] 3D GUI rotation glitching out

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)

Help will be very appreciated.

2 Likes

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)

Alright. This question might sound stupid but what is the best way to implement it?

Would you mind giving a few more details about how exactly the velAttachment fits into the whole system so I can get a better idea of what to do?

Youd probably just directly translate it to cframe like:

velAttachment.CFrame = velAttachment.CFrame:Lerp(CFrame.lookAt(velAttachment.CFrame.p,Vector3.new(-2.5 - cameraAngularVelocity.X, cameraAngularVelocity.Y*-1, 0)), 0.1)

Welp, for some reason it changed it’s orientation now.

Oh sorry, my bad I had a bit of a brainfreeze
Havent done this in a while

Here is the proper code:

velAttachment.CFrame = velAttachment.CFrame:Lerp(CFrame.new(velAttachment.CFrame.p)*CFrame.Angles(math.rad(-2.5 - cameraAngularVelocity.X), math.rad(cameraAngularVelocity.Y*-1), 0), 0.1)

Alot of thanks to you! I was never friends with Lerp in general, so I don’t think I could’ve done it without your help.

1 Like

Sorry to interrupt, but could you explain or link any resources that could be considered helpful to creating a 3D GUI?

I haven’t seen any posts on creating one but I’m very curious on how it is made. SurfaceGUI? Viewport Frame? So lost.

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

1 Like