Rotate Tween w/ pivot offset

I want to tween a chest lid opening by using pivot offset to make the rotation look good

I did this in a game before, it was with a gate and I made the pivot offset work the rotating tween so that it looks like doors opening and not a slab spinning.

I’m trying to use it again for a chest lid but it doesn’t seem to be working. Any idea why or how to get this to work?

(Image this but tweened)

1 Like

What I’d do is create a joint at the hinge area, then unanchor and weld the top part of the chest to the hinge joint. To tween it to open, rotate the part on whatever axis is backwards for it by however much you’d like. You should be able to make that joint the pivot offset.

Did you find out how to do it? Cuz I’m having the same issue

Nah, I think I just found the CFrame of the open chest lid and tweened to that instead. If it’s set up well it should look fine for a basic chest open animation. I probably did something like

local Chest = script.Parent
local openedCFrame = (the cframe of the opened lid)

local TS = game:GetService("TweenSerivce")
TS:Create(Chest.Lid, TweenInfo.new(.5), {CFrame = openedCFrame):Play()

hardest part is getting the opened lid CFrame. I’d just mess around with it until you find what orientation and position changes need to made to get it in spot.

You could also rig a chest model if you want more expressive animations

local tweenService = game:GetService("TweenService")
local runService = game:GetService("RunService")

function TweenPivot(object,offset,tweenInfo)
	local speed,easingStyle,easingDirection = table.unpack(tweenInfo)
	local pivot = object:GetPivot()
	local goal = pivot * offset
	
	coroutine.wrap(function()
		local elapsed = 0
		local alpha = 0
		while alpha < 1 do
			alpha = math.clamp(elapsed /speed,0,1)
			local tween_cf = pivot:Lerp(goal, tweenService:GetValue(alpha,easingStyle,easingDirection))
			object:PivotTo(tween_cf)
			elapsed += runService.RenderStepped:Wait()
		end
	end)()
end
1 Like