So I am making a 2d scrolling game using camera manipulations using this localscript in the StartingPlayerScripts.
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
0.1,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local camera = game.Workspace.Camera
local UserInputService = game:GetService("UserInputService")
local Character = player.CharacterAdded:Wait()
local HumanoidPart =Character:WaitForChild("HumanoidRootPart")
camera.CameraSubject = player.Character.HumanoidRootPart
camera.CameraType = Enum.CameraType.Scriptable
camera.FieldOfView = 50
game:GetService('RunService').Stepped:Connect(function()
local worldPoint = Vector3.new(HumanoidPart.Position.X, HumanoidPart.Position.Y, HumanoidPart.Position.Z)
local vector, onScreen = camera:WorldToScreenPoint(worldPoint)
local screenPoint = Vector2.new(vector.X, vector.Y)
local mousePos = UserInputService:GetMouseLocation()
local distance = math.sqrt( math.pow((screenPoint.X - mousePos.X),2) + math.pow((screenPoint.Y - mousePos.Y),2))
local atan2 = math.atan2(mousePos.Y - screenPoint.Y, mousePos.X - screenPoint.X)
local angle = math.deg(atan2)
local floorAngle = math.floor(angle)
if distance > 160 and floorAngle > -112.5 and floorAngle < -67.5 then
local tween = TweenService:Create(camera, tweenInfo,{CFrame = CFrame.new(Vector3.new(HumanoidPart.Position.x,HumanoidPart.Position.Y+5,HumanoidPart.Position.z + 34))})
tween:Play()
elseif distance > 160 and floorAngle > -67.5 and floorAngle < -22.5 then
local tween = TweenService:Create(camera, tweenInfo,{CFrame = CFrame.new(Vector3.new(HumanoidPart.Position.x+5,HumanoidPart.Position.Y+5,HumanoidPart.Position.z + 34))})
tween:Play()
elseif distance > 160 and floorAngle < 22.5 and floorAngle > -22.5 then
local tween = TweenService:Create(camera, tweenInfo,{CFrame = CFrame.new(Vector3.new(HumanoidPart.Position.x+5,HumanoidPart.Position.Y,HumanoidPart.Position.z + 34))})
tween:Play()
elseif distance > 160 and floorAngle < 67.5 and floorAngle > 22.5 then
local tween = TweenService:Create(camera, tweenInfo,{CFrame = CFrame.new(Vector3.new(HumanoidPart.Position.x+5,HumanoidPart.Position.Y-5,HumanoidPart.Position.z + 34))})
tween:Play()
elseif distance > 160 and floorAngle > 112.5 and floorAngle < 67.5 then
local tween = TweenService:Create(camera, tweenInfo,{CFrame = CFrame.new(Vector3.new(HumanoidPart.Position.x,HumanoidPart.Position.Y-5,HumanoidPart.Position.z + 34))})
tween:Play()
elseif distance > 160 and floorAngle > 157.5 and floorAngle < 112.5 then
local tween = TweenService:Create(camera, tweenInfo,{CFrame = CFrame.new(Vector3.new(HumanoidPart.Position.x-5,HumanoidPart.Position.Y-5,HumanoidPart.Position.z + 34))})
tween:Play()
elseif distance > 160 and floorAngle > 112.5 or floorAngle < -157.5 then
local tween = TweenService:Create(camera, tweenInfo,{CFrame = CFrame.new(Vector3.new(HumanoidPart.Position.x-5,HumanoidPart.Position.Y,HumanoidPart.Position.z + 34))})
tween:Play()
elseif distance > 160 and floorAngle > -157.5 and floorAngle < -112.5 then
local tween = TweenService:Create(camera, tweenInfo,{CFrame = CFrame.new(Vector3.new(HumanoidPart.Position.x-5,HumanoidPart.Position.Y+5,HumanoidPart.Position.z + 34))})
tween:Play()
else
local tween = TweenService:Create(camera, tweenInfo,{CFrame = CFrame.new(Vector3.new(HumanoidPart.Position.x,HumanoidPart.Position.Y,HumanoidPart.Position.z + 34))})
tween:Play()
end
end)
However, after death, the camera stays in place and no longer follows the HumanoidRootPart anymore. Am I doing something wrong here?