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

How to rotate a model and move to a different position?

Asked by 7 years ago

I want to make a large door that swings open on one side and the opposite door swings the other. Since I'm extremely new to scripting, Ive done the following with the model on each individual part, meaning each part needs a different name. Ive made two models, one is the door's first position, the second is the latter position after being "opened"

script.Parent."DoorPosA"."PartName".Transparency = 1
script.Parent."DoorPosA"."SamePart".CanCollide = false

script.Parent.DoorPosB."PartName2".Transparency = 0
script.Parent.DoorPosB."PartName2".CanCollide = true

ive done it so that a clickdetector is used to make one model completely transparent and disable all its collisions, whilst making another model visible and enabling collisions. Doing this makes the door appear to "open", but writing lines for each individual brick is tedious, and the end result isnt very satisfactory. Im sure there is a much more efficient way of doing this, and a way to make it look like the door is swinging open. I would include images of what i am trying to achieve, but im not sure how to attach such files on this website.

0
You would use SetPrimaryPartCFrame most likely Perci1 4988 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

You will want to use CFrames. You can familiarize yourself with CFrame a bit more by reading the Wiki here.

I would also suggest reading about Vector3, if you haven't already, here and here.

For parts, you can use CFrame to change its location and rotation. However, for entire models, you will have to use SetPrimaryPartCFrame. To use SetPrimaryPartCFrame, you will have to either select the Model while in studio and change the PrimaryPart property to whatever part within the Model that you want to act as the primary, or you can do it through a script. Usually the PrimaryPart is set to a Model's part near the center of the Model, but does not always have to be the case. SetPrimaryPartCFrame will set the CFrame of the primary part, while maintaining the orientation of all other parts within the Model.

It will look like this:

MyModel.PrimaryPart = MyModel.MyNewPrimaryPartWithinTheModel
-- ^ This sets the primary part of the model

MyModel:SetPrimaryPartCFrame(CFrame.new(x, y, z))
-- ^ This sets the CFrame of the primary part, while maintaining the orientation of all the other parts within the model

The code above is just a basic outline of how to use SetPrimaryPartCFrame. I highly recommend reading the Wiki pages that I linked at the very top. They will help you immensely if you haven't familiarized yourself already.

Ad

Answer this question