Tween a union orientation from a pivot point

I simply want to make a door rotate from a pivot point using tweens.
But I cant get it to work even if I set a pivot offset orientation value to the union

local left = script.Parent.Left
local right = script.Parent.Right
local prompt = script.Parent.PromptPart.DoorPrompt
local TS = game:GetService("TweenService")
local actionTag = false
local closed = true
local defLeft = left.Orientation
local defRight = right.Orientation
local openLeft = TS:Create(left,TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{Orientation = Vector3.new(defLeft.X,defLeft.Y+90,defLeft.Z)})
local openRight = TS:Create(right,TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{Orientation = Vector3.new(defRight.X,defRight.Y-90,defRight.Z)})

prompt.Triggered:Connect(function()
	if not actionTag then
		actionTag = true
		if closed then
			openLeft:Play()
			openRight:Play()
		else
			
		end
	end
	wait(1)
	actionTag = false
end)

And this is what happens:


(The doors rotates from the center, not the dark brown part)

Any simple fix?

Set the origin position and/or the pivot offset position and/or the pivot offset to the dark brown part.

I think I’ve dealt with this same issue before! It should be very easy to fix. Make sure that the doors are each a “Model” instance, and set the model’s property called “PrimaryPart” to a part which you want the door to rotate around. Make sure that the PrimaryPart is inside of the model.

I’ll show an example of how to use TweenService to fix your issue here. Pretend “Door” represents your door model, and “Hinge” represents the door model’s PrimaryPart.

local openLeft = TS:Create(Hinge,TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{CFrame = CFrame.new(put cframe here)})
local openRight = TS:Create(Hinge,TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{CFrame = CFrame.new(put cframe here)}

You can adjust the TweenInfo, goals, etc. to your liking and to fit your scenario.

Also, you might have to change the position of the hinge, or make 1 hinge on each side of your door

How would that affect the Door itself? This will just rotate the hinge

This doesnt work. It does the same as showed in the image when used with tween service

Set the pivot points to the post.
image

Then, inside the script, you need to tween between two CFrames; 1. the start closed cframe and 2. the finish open cframe.

However, since you want to use the pivot, you cannot simply just tween the CFrame property, you need to use PivotTo(). So the challenge then becomes using a PivotTo method with tweenservice.

There are a few ways to go about doing this, but an easy way is to use a NumberValue and tween the Value property, and when the object’s value changes you update the pivot.

local TS = game:GetService("TweenService")

local start_cf = script.Parent:GetPivot() -- assuming the script is inside the gate
local end_cf = start_cf * CFrame.Angles(0,math.pi*.5,0)

local obj = Instance.new("NumberValue")
obj.Value = 0 -- 0 is closed, 1 is open --
local openLeft = TS:Create(obj,TweenInfo.new(1,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{Value = 1})

obj:GetPropertyChangedSignal("Value"):Connect(function()
	local tween_cf = start_cf:Lerp(end_cf, obj.Value)
	script.Parent:PivotTo(tween_cf)
end)

task.wait(2)

openLeft:Play()

Result:
pivottween

6 Likes

Wow, exactly what I needed. Thanks <3

1 Like

Just try it. Rotating the primary part’s cframe will rotate the entire model