Math.deg gives random values

so i am working on a third person shooter game
Devlogs :-
#Devlog1 Here
#Devlog2 Here
#Devlog3 Here
#Devlog4 Here

in my game i have a custom backpack that shows the items that the player have in a scrolling frame , this is not the problem , the problem is i use viewportframes to make images for the tools and i use math.deg to rotate the camera to make the icon look nice but some times it gives a random value ! i was using math.rad before but changed it to math.deg because of this but it does not fix it

here is a screen shot to make it easier to understand :-
Untitled Project - Roblox Studio 12_4_2024 1_39_42 AM
as you can see the last button image is different from the others

here the code that calculate the camera position :-

local Camera = Instance.new("Camera")
		Camera.Parent = Clone.ViewportFrame
		Clone.ViewportFrame.CurrentCamera = Camera

		local ItemClone = Tool.PrimaryPart:Clone()
		ItemClone.Parent = Clone.ViewportFrame

		ItemClone.Orientation = Vector3.zero
		Camera.CFrame = CFrame.new(ItemClone.Position + ItemClone.CFrame.RightVector * 1.5 , ItemClone.Position) * CFrame.Angles(0 , 0 , math.deg(270))

When you’re cloning the tool, it probably has an offset on it that is affecting the position/rotation

what should i do to get the same result ?

Set the cframe of the item you’re cloning to CFrame.new() * CFrame.Angles() and then do the position operations in the viewportframe

after parenting the item to the viewportframe ?

math.rad is what you should be using.

Are you sure that the object itself isn’t what was rotated oddly?

1 Like

Before

i was using math.rad but the same issue was happening so i switched to math.deg , i rotate the camera only

Switch back to math.rad.

As the issue happened when you were using both rad and deg, and you are only rotating the camera, I can only conclude that the potion bottle thing is at an angle when it is created. Please check that it isn’t.

the item is not showing now after setting it is cframe to CFrame.new(0,0,0) * CFrame.Angles(0,0,0)

all of them have the same rotation as objects

Can you try moving the parts into the workspace (not the viewport) and seeing what they look like

What’s the top down view of them look like?


Hm.

Does the object that gets rotated ‘randomly’ change at all (as in, does the colour of the potion that is affected change, and does the extent of the rotation change)?

2 Likes

no all of the potions are the same mesh , it happen randomly to a random item or more

1 Like

guys i still need your help the problem is not fixed yet

CFrame.Angles takes angles in radians, which ranges from 0 to 2pi. math.deg converts a value, which is assumed to be in radians, to degrees. math.rad does the opposite; it converts degrees to radians. Put math.rad(270) in instead.

i was already already using math.rad but the same issue was also happening so i changed it to math.deg