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

Why does my part orbit when I remove the :Inverse() method on my CFrame?

Asked by 3 years ago
Edited 3 years ago

So I was following the Wiki (https://developer.roblox.com/en-us/articles/CFrame-Math-Operations) and when I got to the "Rotation" Section and they started talking about CFrame:Inverse(), that's when I lost it. I'm having an extremely difficult time understanding why I need to use CFrame:Inverse() in this case scenario.

Here's the finished product code:

local door = game.Workspace.Door
local hinge = game.Workspace.Hinge

local offset = hinge.CFrame:inverse() * door.CFrame; -- offset before rotation
game:GetService("RunService").Heartbeat:connect(function(dt)
    hinge.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(1)*dt*60, 0) -- rotate the hinge
    door.CFrame = hinge.CFrame * offset -- apply offset to rotated hinge
end)

Everything works perfectly. However, when I get rid of the :inverse() method on the hinge.CFrame:inverse() (so it's just hinge.CFrame), the door orbits around the Hinge. I'm having trouble figuring out why that is the case.

Code for when the Door orbits the Hinge:

local door = workspace.Door.Block2
local hinge = workspace.Door.Hinge

local offset = door.CFrame * hinge.CFrame;

game:GetService("RunService").Heartbeat:connect(function(dt)
    hinge.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(1)*dt*60, 0) --Turn this by 1 -- at a consistent rate -- at speed 60
    door.CFrame = hinge.CFrame * offset
end)

See the Object Orbiting the Hinge: https://gyazo.com/826af989bcfe5577ea68c8f2ba05ed36

0
Always use :Connect instead of :connect. In the future, keep that in mind! :connect is bad practise as it is deprecated and nolonger used. RazzyPlayz 497 — 3y

Answer this question