I’ve mainly been a builder for most of my time on Roblox, however, I’ve come across a situation where I need to script on a specific project.
It’s basically an ‘interactive map’ based game. I’m trying to get the default camera view to be sort-of like a birds eye view, where the rotation of the view is fixed on the ground, and you’re able to move your camera around using WASD and zoom in and out (to an extent) using the mouse wheel.
local Game = game
local Workspace = workspace
local RunService = Game:GetService("RunService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = Workspace.CurrentCamera
local function OnRenderStep()
local Pivot = Character:GetPivot().Position
local Distance = (Camera.CFrame.Position - Pivot).Magnitude
Camera.CFrame = CFrame.lookAt(Pivot + Vector3.new(0, Distance, 0.5), Pivot)
end
RunService.RenderStepped:Connect(OnRenderStep)
Yes but what else do I do? I have no scripting experience at all. I don’t know what else I must do, I’ve put a localscript in StarterPlayerScripts, it doesn’t work, nothing changes.
Another thing, it’s kinda working but not exactly like I want it, I need there to be a zoom limit, aswell as a boundary. I basically want it to be a camera like most strategy games.
Here’s the script with a clamp incorporated, check the comments for further information.
local Game = game
local Workspace = workspace
local RunService = Game:GetService("RunService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = Workspace.CurrentCamera
local function OnRenderStep()
local Pivot = Character:GetPivot().Position
local Distance = math.clamp((Camera.CFrame.Position - Pivot).Magnitude, 10, 64) --10 studs is the minimum height and 64 studs is the maximum height.
Camera.CFrame = CFrame.lookAt(Pivot + Vector3.new(0, Distance, 0.5), Pivot)
end
RunService.RenderStepped:Connect(OnRenderStep)
As for moving the mouse to the edge of the screen to move the camera I’d recommend hiring someone from here to do that.