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

How would I use CFrame properly in this scenario?

Asked by
Rinpix 639 Moderation Voter
4 years ago
Edited 4 years ago

I'm trying to make a solar system model and I'm using a part that extends from the center of the sun outwards to the desired position of the planet. The part is supposed to pivot around the center of the sun and the position of the planet is supposed to be updated as it pivots.

This is what I want it to look like. In the end the pivoting part will be invisible and the celestial bodies will be completely opaque.

The two spheres are the Sun and Mercury. The long blue part is the part that will pivot around the center of the Sun, and will have Mercury on the end of it.

This is what I've written to try position it like in the screenshot above:

local planet = game.Workspace.Mercury
local pivot = game.Workspace.Pivot

planet.CFrame = CFrame.new(pivot.Position + Vector3.new(0, 0, -pivot.Size.Z/2))

But, instead, it positions it like this.

I know that this is happening because I'm not taking the orientation of the pivot part into account, but I don't know how to alter the code to compensate for that.

I would appreciate any help.

EDIT:

Nevermind. I found the solution.

local planet = game.Workspace.Mercury
local pivot = game.Workspace.Pivot

planet.CFrame = CFrame.new(pivot.Position) * CFrame.Angles(0, math.rad(pivot.Orientation.Y), 0) * CFrame.new(-pivot.Size.X/2, 0, 0)

Answer this question