Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can't rotate a Model with a script?

Asked by 4 years ago

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.

  1. I looked on the Dev page at the Models article, and looked at the functions available. I found nothing.
  2. I tried using a script to rotate the NPC's Torso. I thought since the other parts were welded together to this part, changing its Orientation would move everything else in the NPC along with the Torso. Here's the script:
-- 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!

1
A little Coment on eternal_silverfox. If you still rotating the orientation of script.Parent (With fromEularAngle), don't use fromEularAngleXYZ, use fromEularAnglesYXZ. Though if your using cframes, the ladder works perfectly fine. Farsalis 369 — 4y
0
My bad, meant YXZ. Jahaziel_VanDerHas 238 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

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.

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)

Answer this question