I've been trying to find a way to rotate a Model with a script. If you want me to be specific, I am trying to make an NPC (Non-Player Character) Model rotate to a certain degree for cut-scenes in a game.Here are some things I tried.
-- This is parented to an NPC's Torso script.Parent.Orientation = Vector3.new(script.Parent.Orientation.X, script.Parent.Orientation.Y + 90, script.Parent.Orientation.Z)
This did not work.
I'm not sure what to do. Please leave any solutions you know of as an answer. Bye!
Make sure your NPC Model has a PrimaryPart set (HumanoidRootPart or Torso), and Model:SetPrimaryPartCFrame(cframe)
You can construct a CFrame with a particular direction and world position easily many ways, such as:
local cf = CFrame.fromOrientation(ox, oy, oz) + Vector3.new(x,y,z)
Where ox, oy, and oz are orientations yaw, pitch and roll in Radians and x,y,z is the world position. If you want to specify angles in degrees, use math.rad(degrees)
which returns the Radians value or just do the arithmetic. It's a simple linear scaling: 180 degrees is math.pi
Radians.
Note that if you get Part.Orientation, you get a tuple of Degrees, not Radians.
Model:SetPrimaryPartCFrame()!
You first need to set a part as the "PrimaryPart", think of it like the RootPart of the model. Do so in studio or assigning a Part to it by script.
Everything will move respect to it.
--EXAMPLE local originalCFrame=script.Parent.PrimaryPart.CFrame local rotation=CFrame.fromEulerAnglesYXZ(0,math.rad(90),0) --fromEulerAngles does the calculation like .Orientation would, and math.rad transforms degrees to radians, which are used with CFrames. script.Parent:SetPrimaryPartCFrame(originalCFrame*rotation)