Position part relative to itself

im making a door that is just a single part and i want it to open as if it has a hinge
the problem is it doesnt work when i rotate it

i want it to work regardless of its position and orientation

this is the code that im using:

Model:PivotTo((CFrame.new(Model:GetPivot().Position) + Vector3.new(-2.5, 0, -2.5)) * CFrame.Angles(0, 0, math.rad(90)))

this is the position of the part that works with this code:

cframes eat me up i really dont get them

2 Likes

local pivot = Model:GetPivot()
local hingeOffset = CFrame.new(-2.5, 0, -2.5) – local hinge offset
local rotation = CFrame.Angles(0, 0, math.rad(90))

Model:PivotTo(pivot * hingeOffset * rotation * hingeOffset:Inverse())

chatgpt is really good at this kind of stuff btw

chat gpt is like asking donald trump to explain anything
and it gave me this exact thing that doesnt work right

What I would first do is set the pivot position to the hinge using the editor:

Then, in the code, just multiply the pivot by a rotational vector:

Model:PivotTo(Model:GetPivot() * CFrame.Angles(0, math.rad(90), 0))

If the door rotates in the wrong direction, instead of modifying the Y rotation, try doing the X or Z.

1 Like

This is identical to what the original code does, I’m not sure why you replied without testing.

tysm! i didnt know you could change the offset of the pivot

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.