Tweening Players Camera While Player Is Moving

My game is trying to act as if it is 2D - playing while looking down onto the player, the players camera is locked by repeating heartbeat and cannot be moved, sometimes though the Y axis of the camera which is how far away from the player the camera is ,can change which is with what i have the problem.

The way i tried to do that was by using tweens, turning off heartbeat and then tweening up and then heartbeat on new High from player again, the problem is the tween won’t follow the player (if the player is moving, in theory it works perfectly but the player would need to be still which in most cases they won’t be) and just tween up in one axis while the heartbeat could follow player in X and Z axis.

I also tried lerp but it’s not what i’m looking for.

Thank You for any help

local Tweening = false
PlayerCameraHighness = 50
local function CreateAndPlayTween(Duration)
	local Info = TweenInfo.new(
		Duration,
		Enum.EasingStyle.Quad,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local Tween = TweenService:Create(Camera, Info, {CFrame = CFrame.new(Hum.Position.X, PlayerCameraHighness, Hum.Position.Z) * CFrame.Angles(math.rad(-90), 0, 0)})
	Tween:Play()
	Tween.Completed:Wait()
end

CreateAndPlayTween(2)

game:GetService("RunService").Heartbeat:Connect(function()
	if Tweening then
		CreateAndPlayTween(1)
		Tweening = false
	else
		Camera.CFrame = CFrame.new(Hum.Position.X, PlayerCameraHighness, Hum.Position.Z) * CFrame.Angles(math.rad(-90), 0, 0)
	end
end)

Unless you run a short tween every frame, lerping seems like the only method to do this. TweenService just won’t work for what you’re trying to achieve since you can’t update the target values.
I don’t understand the issue with lerping since it basically is tweening but easier when used every frame.

To spawn, player has to click a Play ui button, afterwards it will tween a camera from up high to the set location above the player, but with the tween the player can move away and the camera will tween to where they spawned at.

Of course i could anchor the player until it tweens but that’s decrading towards the play experience.

And using a lerp to move the camera like that from top was never as nice and smooth as the tween.

I’ve implemented a lerp, I believe it will be much smoother.

Code:

local Tweening = false
PlayerCameraHighness = 50
local function CreateAndPlayTween(Duration)
	local Info = TweenInfo.new(
		Duration,
		Enum.EasingStyle.Quad,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local Tween = TweenService:Create(Camera, Info, {CFrame = CFrame.new(Hum.Position.X, PlayerCameraHighness, Hum.Position.Z) * CFrame.Angles(math.rad(-90), 0, 0)})
	Tween:Play()
	Tween.Completed:Wait()
end

CreateAndPlayTween(2)

game:GetService("RunService").PreRender:Connect(function(deltaTime)
	local targetCFrame = CFrame.new(Hum.Position.X, PlayerCameraHighness, Hum.Position.Z) * CFrame.Angles(math.rad(-90), 0, 0)
	
	if Tweening then
		Camera.CFrame = Camera.CFrame:Lerp(targetCFrame, deltaTime)
	else
		Camera.CFrame = targetCFrame
	end
end)

I tried to switch to the Lerp but it was acting odd.

I use a script that sets the camera cframe before the player spawns (video).
That was the main cause of issues for some reason, but even when not enabled, the lerp was affecting the players movement for some reason (videos).

External Media External Media

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.