Hey, so I’m working on a top down shooter styled like black ops zombies arcade and my orbital camera script is complete, however when rapidly scrolling, it causes the player to die.
Below is the code,
local ws = game:GetService("Workspace")
local hb = game:GetService("RunService")
local ts = game:GetService("TweenService")
local rep = game:GetService("ReplicatedStorage")
local uis = game:GetService("UserInputService")
local plrs = game:GetService("Players")
local rs = game:GetService("RunService")
local plr = plrs.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local mouse = plr:GetMouse()
local cam = workspace.CurrentCamera
local events = {}
local Zoom = 45
local DeltaY = 0
local CFNew, CFAng = CFrame.new, CFrame.Angles
local Asin = math.asin
game:GetService("UserInputService").InputChanged:Connect(function(input)
local inputType = input.UserInputType
local mouse1 = Enum.UserInputType.MouseMovement
if input.UserInputType == Enum.UserInputType.MouseWheel then
DeltaY = -input.Position.Z
if Zoom < 0.1 and DeltaY < 0 then
DeltaY = 0
end
if DeltaY > 0 and Zoom > 1000 then
DeltaY = 0
end
wait()
DeltaY = 0
end
end)
function CamMovement()
return game:GetService("RunService").RenderStepped:Connect(function()
if DeltaY == -1 and Zoom > 40 or DeltaY == 1 and Zoom < 50 then
Zoom = Zoom + DeltaY * (Zoom / 6)
end
-- local direction = (mouse.Hit.p - char.HumanoidRootPart.Position) * Vector3.new(1, 0, 1)
-- char.HumanoidRootPart.CFrame = CFrame.new(char.HumanoidRootPart.Position, char.HumanoidRootPart.Position + direction)
local plrPos = char.PrimaryPart.Position
local camPos = plrPos + Vector3.new(0, Zoom, 0)
workspace.CurrentCamera.CFrame = CFrame.new(camPos, plrPos)
end)
end
events["CamMove"] = CamMovement()