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

Rotating around a point?

Asked by 9 years ago

How can I get a part to rotate around a point? Say I have a brick 5 units in front of a point, how would I rotate it 180 degrees around the point while maintaining its distance?

0
Script-wise, or otherwise? There are alternatives. iUnEarthly 85 — 9y
0
What exactly are you looking to do with this? I've got a few solutions for a few cases. User#6546 35 — 9y
0
Would just writing a function for this be fine? I don't know what you want. Goulstem 8144 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

CFrame

A simple implementation of CFrame.Angles will do the trick. CFrame.Angles returns a rotation with 3 given axes (X,Y,Z), in radians.

Radians overview

In case you don't know how radians work, I'll provide a quick overview. Radians are basically a different form of measurements for a circle (oppose to degrees). But, they can work the same way. An example of radians you're probably familiar with is Pi (3.14...) which represents half a rotation in radians. Therefore 2*Pi = 360 degrees, which is a full circle in radians (6.28...)

Anyway, with that out of the way, I'll give you an example:

local Point = CFrame.new(0,10,0) -- The point the object will rotate around
local Offset = CFrame.new(0,0,10) -- the offset of the part (distance from it)

local Object = Instance.new("Part",workspace)
Object.Anchored = true

while true do

    -- Each iteration, we're making the Object's CFrame equal to the Point's CFrame, multiplied by the rotational CFrame, then again multiplied by the offset.

    -- "math.rad" simply converts it's numeric argument to radians.

    for i = 1,360 do
        Object.CFrame = Point * CFrame.Angles(0,math.rad(i),0) * Offset
        wait()
    end
end

Note

I'm not gonna cover the entire CFrame library, so if you're not experienced in it, I suggest this wiki page: http://wiki.roblox.com/index.php?title=CFrame#Constructors

Hope this helped, let me know if you have any questions.

0
thanks, that's exactly what I was looking for aquathorn321 858 — 9y
0
Is it possible to apply this to a Tween? The problem I run into is that instead of rotating *around* the point, it just goes through it, when doing a 180 degree rotation. AzrefriskDreemurr 8 — 3y
Ad

Answer this question