Going about transitioning CFrame overtime

So i’m working on a small horror game and I was wondering how I would go about creating a system that will slowly Open a door based on a Number value that I have placed. How the door works is there is 2 points, StartPoint and EndPoint. I want to transition a door from the Startpoint to the end point based on the Number Value. Almost using it as a percentage. All replys are helpful thanks!

Is this an overtime thing or are there other conditions for the number to increase?
If it is, I suggest you look at TweeningService.

1 Like

It’s more about they way I’m getting them to move based on a value like a percentage if that makes sense.

Here is a crappy MS paint picture that might make it a bit clearer, Sorry that I said it badly the first time

How about this? It’s simplified example code to rotate a door based off a number value between 0 and 1

local tweenService = game:GetService("TweenService")
local door = workspace.randomDoor
originalAngle = door.Orientation.Y -- the original angle of the door to remember
local originalCFrame = door.CFrame
endAngle = originalAngle + 90

function tween(object, info, goal) -- i commonly use this function to tween quickly
	local newTween = tweenService:Create(object, info, goal)
	newTween:Play()
end

function rotateDoor(newRotation)
	-- rotate the door to the new rotation
	local newAngle = (endAngle - originalAngle) * newRotation + originalAngle -- use math to find the angle between the original and new angle
	tween(door, TweenInfo.new(1), {
		CFrame = originalCFrame * CFrame.Angles(0, math.rad(newAngle), 0)
	}) -- weird cframe angle stuff, apparently using * is like adding a cframe onto another
end

door.rotationValue:GetPropertyChangedSignal("Value"):Connect(function()
	print("new value is " .. door.rotationValue.Value)
	rotateDoor(door.rotationValue.Value)
end)

Apologies if this is just me throwing a block of code at you without explaining most of it, but hopefully some of the things in it are useful. This only works on a part and not a model, so you’ll probably have to adapt this code and your door to be able to tween models.

2 Likes

Works like a charm, thanks alot!

1 Like