Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Rotating a part around a point using TweenService?

I'm making a door that rotates around a hinge (Not an actual HingeConstraint). The first thing that came to my mind was to use TweenService to rotate it on the hinge, however I just cant seem to get it working. I thought about using CFrames but I don't quite understand how they work. Any suggestions?

3 comments

0

why dont you just change the rotation value on the part?

0

Roblox, by default, rotates parts around their center point.

0

set the primarypart of the model to the hinge and rotate that (assuming the door and hinge is grouped apart from the entire door)

1 answer

✓ Accepted answer

There's this thing called CFrame:ToWorldSpace(), function transforms an object’s Coordinate-Frame — respecting its own local orientation — to a new world orientation. This makes it ideal for offsetting a part relative to itself or another object, regardless of how it’s currently positioned/rotated.

In the code below, notice that the Door gets offset 2 studs relative to the Y axis of the hinge (the up and down axis) and not relative to the global Y axis pointing straight up.

local Door = game.Workspace.Doorframe
local DoorHinge = game.Workspace.Hinge
 
local offsetCFrame = CFrame.new(0, 2, 0)
Door.CFrame = DoorHinge.CFrame:ToWorldSpace(offsetCFrame)

If you test this now, it looks like the part, Doorframe is connected to the part, Hinge. Add a loop onto the script above, then make the hinge spin. If you dont know how to use CFrames, read this article on roblox. -- https://developer.roblox.com/en-us/articles/Understanding-CFrame

1 comment

0

hi

This discussion is preserved as it was. New answers, comments, and votes are closed.