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

How do I make an anchored brick face a specific brick at all times?

Asked by 9 years ago

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.

0
I'd just like to point out that Referring to script.Parent as "Parent", can cause issues BSIncorporated 640 — 9y
0
Wait about a day while I get my calculus book out. This involves rotation matrices. DewnOracle 115 — 9y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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)

Ad

Answer this question