Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I set an angle instead of adding an angle?

I am trying to set the Y rotation of a part on its own axis, but when I do CFrame = CFrame * CFrame.Angles(), It adds the Angles to the current Angle. Is there any way I can just set the Angle while still keeping the object rotating on it's own Y axis?

1 answer

yes there is. This is what you would have to do. Create a new CFrame containing only the position of the previous CFrame. And then add your angle to the new CFrame. Example on how this would be done:

-- Let's imagine this is our CFrame
local MainCFrame = CFrame.new(10,3,1) * CFrame.Angles(0,math.pi,0)


-- We create a new cframe that has the position of our old cframe
local position = CFrame.new(MainCFrame.p)

-- We create a cframe that has new an angle.
local orientation = CFrame.Angles(0,math.rad(90),0)

-- we merge them together into one cframe 
local RotatedCFrame = position * orientation

2 comments

0

Do you know where I would have to place these if it were in a renderstepped function? I am not sure how I would get the last position because the function updates every render.

0

Could you provide that script so that we can take a closer look?

This discussion is preserved as it was. New answers, comments, and votes are closed.