The problem that I’m currently facing is the camera not updating to the current position after tweening.
I have a smooth camera script which I took straight from the toolbox, and from what I understand, this is happening because once the tween plays, the variable of the mouse angle, movement is stored, so when I run the smooth camera function again it puts it to where it was before. I want to make it so that the camera stays where it is even after the tween, and to reset the mouse angle, movement variable.
The function that stores the mouse movement in order for the smooth camera to work
input.InputChanged:connect(function(inputObject)
if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
local delta = Vector2.new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * Smoothness
local X = TargetAngleX - delta.y
TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X
TargetAngleY = (TargetAngleY - delta.x) %360
end
end)
A part of the main smooth camera script that sets the position of the camera
runService.RenderStepped:connect(function()
if running then
updatechar()
CamPos = CamPos + (TargetCamPos - CamPos) *0.28
AngleX = AngleX + (TargetAngleX - AngleX) *0.35
local dist = TargetAngleY - AngleY
dist = math.abs(dist) > 180 and dist - (dist / math.abs(dist)) * 360 or dist
AngleY = (AngleY + dist *0.35) %360
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = CFrame.new(head.Position)
* CFrame.Angles(0,math.rad(AngleY),0)
* CFrame.Angles(math.rad(AngleX),0,0)
* HeadOffset
else game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
end
My function which aims to tween the camera to a position, after doing so runs the smooth camera function again
rep.RE.FaceCam.OnClientEvent:Connect(function(pos)
runback = true
running = false
Controls:Disable()
local move_cam = tweenservice:Create(cam, TweenInfo.new(), {CFrame = CFrame.lookAt(cam.CFrame.Position, pos)})
move_cam:Play()
humanoidpart.CFrame = CFrame.lookAt(humanoidpart.CFrame.Position, pos)
move_cam.Completed:Wait()
Controls:Enable()
running = true
end)
What I hope happens:
What happens: