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.
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
