I currently have an Isometric style camera, however i’m currently trying to make it so when the mouse passes for example 75% of the screen, the camera will shift slightly in the direction of the mouse.
When mouse crosses 70% of screen on x axis I want it to shift the camera, what are the steps i need to do to accomplish this?
Current camera script:
RunService.RenderStepped:Connect(function()
if character then
if character:FindFirstChild("Head") and character:FindFirstChild("HumanoidRootPart") then
game:GetService("SoundService"):SetListener(Enum.ListenerType.ObjectCFrame, character.Head)
camera.CFrame =
CFrame.new(Vector3.new(character.HumanoidRootPart.Position.X + zoom, character.HumanoidRootPart.Position.Y + zoom, character.HumanoidRootPart.Position.Z + zoom), character.HumanoidRootPart.Position)
end
end
end)
It’s probably possible but just not sure where to begin never made anything like this so its a bit out of my zone, If you’re familiar with project zomboid, a steam game, that camera system is what i’m aiming for mainly
local RunService = game:GetService("RunService");
local UIS = game:GetService("UserInputService");
local character = script.Parent;
local humanoidRootPart: BasePart = character.HumanoidRootPart;
game:GetService("SoundService"):SetListener(Enum.ListenerType.ObjectCFrame, character.Head)
local camera: Camera = workspace.Camera;
camera.CameraType = Enum.CameraType.Scriptable;
local fraction: number = 0.7; -- how much of the screen (0.7 = 70%)
local remainders: number = (1 - fraction) / 2;
local step = 3; -- greater = narrower view, smoother
-- smaller = wider view, less smooth
RunService:BindToRenderStep("CustomCamera", 200, function()
local viewportSizeX: number = camera.ViewportSize.X;
local zoom: number = 20;
local bound1: number = viewportSizeX * remainders;
local bound2: number =
viewportSizeX * fraction + viewportSizeX * remainders;
local lookAt: CFrame = CFrame.new(humanoidRootPart.Position + Vector3.new(zoom, zoom, zoom),
humanoidRootPart.Position);
local mouseX = UIS:GetMouseLocation().X;
camera.CFrame = lookAt;
if mouseX <= bound1 then
local offset = math.sqrt(bound1 - mouseX);
offset /= step;
camera.CFrame += Vector3.new(-offset, 0, offset);
elseif mouseX >= bound2 then
local offset = math.sqrt(mouseX - bound2);
offset /= step;
camera.CFrame += Vector3.new(offset, 0, -offset)
end
end)