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

How do I changed the orientation of a model using script?

Asked by
Cowgato 33
1 year ago

I've figured out how to change the position of a model using MoveTo, but I am not sure what piece of script will allow me to also change the orientation of the model. (I have already set the primary part for the model which is called 'MainDoor')

script.Parent.Touched:Connect(function()
    game.Workspace.MainDoor:MoveTo(Vector3.new(73.366, 3.843, -7.959))
--line of code to change orientation of MainDoor
    script.Parent:Destroy()
end)
0
We were already helping you on your other question... Why did you create a new one? Kingu_Criminal 205 — 1y
0
Hi there, I've already solved the problem on the other post recently, but I'm not sure how to change the orientation now. Cowgato 33 — 1y
0
I don't understand why are you using :MoveTo to move a model. Use :SetPrimaryCFrame() instead (altrough it's deprecated). It has much more possibilites. SuperPuiu 497 — 1y
0
I would like to use CFrame but I don't know how to use it to make it go to the specific coord I want Cowgato 33 — 1y

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

You can rotate and move models using :PivotTo(). This is function that can be used to make a model to go a CFrame with a set angle. To make the model only rotate, this can be easily done. Try this piece off code:

script.Parent.Touched:Connect(function()
    game.Workspace.MainDoor:MoveTo(Vector3.new(73.366, 3.843, -7.959))
    game.Workspace.MainDoor:PivotTo(game.Workspace.MainDoor:GetPivot() *  CFrame.Angles(math.rad(90,0,0),0,0))
    script.Parent:Destroy()
end)

All that I have added is game.Workspace.MainDoor:PivotTo(game.Workspace.MainDoor:GetPivot() * CFrame.Angles(math.rad(90,0,0),0,0)), so I will explain that now. First, we get the model which is the MainDoor. We then call :PivotTo(). This will be used to change the pivot. In the brackets, we then get the model again and call :GetPivot() to get the model's current pivot. We then times that pivot by a angle cframe, 90, 0, 0. math.rad converts an angle in degrees to radians. This should then rotate the model.

Some useful links:

Edit: I have replaced game.Workspace.MainDoor:PivotTo(game.Workspace.MainDoor:PivotTo:GetPivot * CFrame.Angles(math.rad(90,0,0),0,0)), with game.Workspace.MainDoor:PivotTo(game.Workspace.MainDoor:GetPivot() * CFrame.Angles(math.rad(90,0,0),0,0)), so I will explain that now. to fix a error

0
There is an error which underlines (game.Workspace.MainDoor:PivotTo:GetPibot * CFrame.Angles(math.rad(90,0,0),0,0)) Cowgato 33 — 1y
0
Oops - Thats my blame from copy and pasting, Fixed it. Jay123abc2 241 — 1y
Ad

Answer this question