Here is my orbit script. I need to modify it so that the part that orbits has a specific face constantly face a specified brick while orbiting.
Parent = script.Parent Rotate = script.Parent.Parent.LeaderboardRotate while wait() do local t = tick() * (math.pi * 2) * .1 -- 1.5 revolutions per second local orbit = Vector3.new( math.cos(t), 0, math.sin(t) ) Parent.CFrame = CFrame.new( Rotate.Position + orbit * 7 ) end
"Parent" is the brick that is orbiting. "Rotate" is the brick it is orbiting.
CFrame.new
has a convenient constructor that takes two Vector3s, from
and to
and produces a CFrame looking from from
and toward to
.
For instance, the following will make Parent
move the same way it did before, but always look towards Rotate
:
Parent.CFrame = CFrame.new( Rotate.Position + orbit * 7, Rotate.Position )
By "towards", I mean the Front-face is pointing in the direction of the to
, and the Top-face is roughly pointing up (as opposed to down, or left, or whatever)