Hello!
I started using CFrame and I decided to make something with it.
But the problem is, CFrame.Angles isn’t working correctly!
I tried finding a solution on this forum but I didn’t find anything relevant.
The Script
local Button = script.Parent
local ClickDetector = Button.ClickDetector
local TextLabel = script.Parent.Parent.Parent.Screen.CodeScreen.SurfaceGui.TextLabel
ClickDetector.MouseClick:Connect(function()
if TextLabel.Text == "696969" then
TextLabel.Text = "Access Granted! Opening Door..."
wait(2.9)
script.Parent.Parent.Parent.Parent:SetPrimaryPartCFrame(script.Parent.Parent.Parent.Parent:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, 45))
script.Parent.Parent.Parent.Parent:SetPrimaryPartCFrame(script.Parent.Parent.Parent.Parent:GetPrimaryPartCFrame() * CFrame.Angles(-47.5, 3.975, 128.25))
end
end)
Any help will be appriciated!
1 Like
Can you send a video/gif/screenshot(s) of what it’s supposed to look like and what’s happening?
Brickman808
(NonFunctionalProgram)
July 19, 2021, 8:26pm
#3
That is because CFrame.Angles defines its axis in radians and not in degrees.
thatrandomnoob23:
CFrame.Angles(0, 0, 45)
Should be CFrame.Angles(0, 0, math.pi / 4)
.
2 Likes
Good point, @thatrandomnoob23 make sure you use math.rad(angles ) to make the angles degrees instead of radians
1 Like
Try this:
local Button = script.Parent
local ClickDetector = Button.ClickDetector
local TextLabel = script.Parent.Parent.Parent.Screen.CodeScreen.SurfaceGui.TextLabel
ClickDetector.MouseClick:Connect(function()
if TextLabel.Text == "696969" then
TextLabel.Text = "Access Granted! Opening Door..."
wait(2.9)
script.Parent.Parent.Parent.Parent:SetPrimaryPartCFrame(script.Parent.Parent.Parent.Parent:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, math.rad(45)))
script.Parent.Parent.Parent.Parent:SetPrimaryPartCFrame(script.Parent.Parent.Parent.Parent:GetPrimaryPartCFrame() * CFrame.Angles(math.rad(-47.5), math.rad(3.975), math.rad(128.25)))
end
end)
2 Likes
Its possible that you are rotating it on the wrong axis
2 Likes
Actually, I moved it to the position I wanted it to be then copyed the Position
property. Same for the Orientation
property.
1 Like
Did you copy the X, Y and Z orientation and put them here?
script.Parent.Parent.Parent.Parent:SetPrimaryPartCFrame(script.Parent.Parent.Parent.Parent:GetPrimaryPartCFrame() * CFrame.Angles(math.rad(-47.5), math.rad(3.975), math.rad(128.25)))
1 Like
Changed the orientation to it’s normal configuration and now I have this:
Not exactly it’s original configuration. I just moved the math.rad(45)
to the middle.
I’m confused, when I was reading your script, it seems you only need this line to rotate the door.
script.Parent.Parent.Parent.Parent:SetPrimaryPartCFrame(script.Parent.Parent.Parent.Parent:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, math.rad(45)))
Could you explain why you need this line?
script.Parent.Parent.Parent.Parent:SetPrimaryPartCFrame(script.Parent.Parent.Parent.Parent:GetPrimaryPartCFrame() * CFrame.Angles(math.rad(-47.5), math.rad(3.975), math.rad(128.25)))
1 Like
The first one is for rotating the “heavy security door” and the second one for moving it.
1 Like
The second one is also rotating the door
1 Like
Wait how? I don’t know much about CFrame
.
1 Like
CFrame.Angles is used to rotate parts. To move a part, you can use CFrame.new
1 Like
CFrame.Angles()
applies in ZYX order, make sure that your rotations, if done in ZYX order produce the same result, because rotating an object means changing the planes it rotates around. If you rotate 90 degrees around the z axis, your y axis is now where your x axis was:
as you can see, red (x) and green (y) swap places when rotating by 90 degrees around blue (z).
3 Likes
koziahss
(Agent_Invalid)
July 19, 2021, 8:48pm
#19
Are you sure you are using the correct part?
For gettigng the rotations
Why not try moving it only on the Y axis only?
1 Like
My PrimaryPart
is the thicker part between the diamond plate parts.
1 Like