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

How do I rotate an object based on another part's position and orientation?

Asked by 4 years ago

So I have A part. And there's a rotated version of that part but it's in a different place. What I'm trying to accomplish is kind of like opening a briefcase or something like that. It opens on the hinges until it can't open any more (in this case, I want it to stop rotating at the second position / part) How would I accomplish this?

1 answer

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

It all starts with...

CFrame

CFrame is an object oriented datatype that lets you move and rotate things! CFrame is similar to Vector, but the difference is that CFrame includes Orientation

Here is a example

local MyCFrame = game.Workspace.Part1.CFrame
print(MyCFrame)

Now, this may look confusing but it's not. It's printing the orientation and the position.

First lets learn how to move parts with CFrame.

local Case = game.Workspace.Part1

Case.CFrame = Case.CFrame * CFrame.new(0, 10, 0)

"Why are we setting the CFrame equal to itself times itself?"

Well, actually if we just do

Case.CFrame * CFrame.new(0, 10, 0)

It would not know what to do with the CFrame.

And we're not multiplying it by itself, It means we're adding it to it's original CFrame.

Moving on....

Now to the orientation like in your suitcase script

local Case = game.Workspace.Part1

Case.CFrame = Case.CFrame * CFrame.Angles(0,math.rad(90), 0)

"What is math.rad, and why do we use it?"

Math.Rad converts it into degree otherwise it would think we were moving it.

Hey, don't be ashamed if you think it's hard, your not the only one :)

0
You're a legend! Thank you for the help! Skychiild 4 — 4y
0
No problem!! :D maxpax2009 340 — 4y
Ad

Answer this question