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

How to Rotate Around a Point?

Asked by 9 years ago

I have scoured the wikis far and wide. I have viewed the YouTube videos, but with no results. The question: How do I rotate an object around a certain point instead of its center? Sorry if this seems lazy, but trust me I have searched. ~yoman1776

2 answers

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

Utilize Object Space!

Here's an example:

01local Center = CFrame.new(12, 165, 124)
02local Part = workspace.Part
03local i = 0
04while true do
05    Part.CFrame = Center:toWorldSpace(
06        CFrame.new(
07            Vector3.new(
08                math.cos(math.rad(i)),
09                0,
10                math.sin(math.rad(i))
11            )*10,
12            Center.p
13        )
14    )
15    --The syntax for this is <BASECFrame>:toWorldSpace(<CFrame in BASECFrame's Object Space>)
16    --The inverse is then <BASECFrame>:toObjectSpace(<CFrame in World Space to Convert to BASECFrame's Object Space>)
17    --I.e. Center:toObjectSpace(Part.CFrame)
18    i = (i + 1)%360
19end

Obviously, the math for this is harder if you want to rotate around an arbitrary axis, but the gist of it is there.

Ad
Log in to vote
0
Answered by 9 years ago

http://wiki.roblox.com/index.php?title=Joint <- Scroll to the bottom, there should be a few examples

Basically you make a hinge, set the two parts, and edit the C0 and C1 properties, dont ask me how to set the C1 and C0 properties, I haven't found an easy way to do it

Answer this question