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

Rotating a part around a point using TweenService?

Asked by 2 years ago

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?

0
why dont you just change the rotation value on the part? VikkiVuk 74 — 2y
0
Roblox, by default, rotates parts around their center point. wwwaylon09 113 — 2y
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) greatneil80 2647 — 2y

1 answer

Log in to vote
1
Answered by 2 years ago

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

0
hi snowpototoy 37 — 2y
Ad

Answer this question