Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I smoothly tween a camera movement to a moving object?

Issue: So I'm currently working on a custom gun system for a group that I work for. The guns are in over the shoulder third person. When you aim, it smoothly tweens the camera toward the player. My issue is that if you move while the tween is taking place, the camera has to teleport to your location. I'd rather have a solution that does not require stopping the player's movement as that would be annoying in the middle of a fight.

What I have

What I'd like to see

Part of the script in charge of tweening the camera (Ran in RunService.Heartbeat):

local startCFrame = CFrame.new((rootPart.CFrame.p + Vector3.new(0,2,0)))*CFrame.Angles(0, math.rad(xAngle), 0)*CFrame.Angles(math.rad(yAngle), 0, 0)

local cameraCFrame = startCFrame + startCFrame:vectorToWorldSpace(Vector3.new(zoomPos.X,zoomPos.Y,zoomPos.Z))
--zoomPos is the vector3 offset
local cameraFocus = startCFrame + startCFrame:vectorToWorldSpace(Vector3.new(zoomPos.X,zoomPos.Y,-50000))
				
if prevState ~= 2 then --state 2 is aiming or scoping
				
	local tween = tS:Create(cam, TweenInfo.new(0.5), {CFrame = CFrame.new(cameraCFrame.p,cameraFocus.p)})
	tween:Play()
					
	tween.Completed:Wait()
				
else
					
	cam.CFrame = CFrame.new(cameraCFrame.p,cameraFocus.p)
				
end

1 answer

I'm dumb and didn't use field of view to zoom the camera in, for anyone wanting to zoom in towards the player it's best just to tween the field of view

This discussion is preserved as it was. New answers, comments, and votes are closed.