I'm developing a game that includes two objects (which will eventually be a camera and a planet), and this requires a relative lookvector between the two objects. Ideally, the relative lookvector will allow the player's camera to rotate with the planet.
I have already tried making my own lookvector with CFrame using ToEulerAnglesXYZ. However, the camera (FollowPart) drifts off in the wrong direction when using this code:
local FollowPart = script.Parent
local RelativePart = workspace.RelativePart
local RelativeCFrame = CFrame.new(RelativePart.Position - FollowPart.Position)
local Speed = 0.05
while wait() do
local X1,Y1,Z1 = FollowPart.CFrame:ToEulerAnglesXYZ()
local X2,Y2,Z2 = RelativePart.CFrame:ToEulerAnglesXYZ()
local TestVector = CFrame.Angles(X1-X2,Y1-Y2,Z1-Z2).LookVector
print(math.deg(TestVector.Y))
FollowPart.CFrame = RelativePart.CFrame*RelativeCFrame*CFrame.Angles(0,math.rad(25),0)
RelativeCFrame = CFrame.new(RelativeCFrame.Position + TestVector*Speed)
end
I have also tried subtracting the camera's lookvector from the planet's (relativeparts) lookvector but this doesn't work either.
How do I make the camera follow the planet's rotation - no matter the camera's orientation?

2 comments
Case sensitive on line 2 Roblox is very picky "WorkSpace"
Workspace*