Hello, I’m attempting to make the top-down camera rotate when you hold down Button2. However, it’s not quite producing the desired results:
Code
local RunService = game:GetService('RunService')
local HRP = script.Parent:WaitForChild('HumanoidRootPart')
local Camera = workspace.CurrentCamera
local Player = game:GetService('Players').LocalPlayer
local Mouse = Player:GetMouse()
local Height = 20
local Button2Down = false
local Eye = Instance.new('Part')
Eye.Name = 'Eye'
Eye.Size = Vector3.new(0.05, 0.05, 0.05)
Eye.Transparency = 1
Eye.CanCollide = false
Eye.Parent = workspace
local BP = Instance.new('BodyPosition')
BP.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BP.Parent = Eye
Camera.CameraType = Enum.CameraType.Scriptable
Eye.CFrame = CFrame.new(HRP.Position + Vector3.new(0, Height, 0), HRP.Position)
function GetMidwayPoint(MouseHit)
return (HRP.Position + MouseHit)/2
end
Mouse.Button2Down:Connect(function()
Button2Down = true
end)
Mouse.Button2Up:Connect(function()
Button2Down = false
end)
RunService.Heartbeat:Connect(function()
local NewMouseHit = Vector3.new(Mouse.Hit.X, Eye.Position.Y, Mouse.Hit.Z)
local MidwayPoint = GetMidwayPoint(NewMouseHit)
BP.Position = MidwayPoint + Vector3.new(0, Height, 0)
Camera.CFrame = Eye.CFrame
if Button2Down then
Eye.CFrame = CFrame.lookAt(Eye.Position, NewMouseHit)
end
end)