Hey everyone, I’ve been working on this isometric camera system, but it locks the camera in place i cannot rotate it on the X axis only.
here is my code:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local cd = 64
local hos = 2
camera.FieldOfView = 20
local function updcam()
local chr = player.Character
if chr then
local humr = chr:FindFirstChild("HumanoidRootPart")
if humr then
local humrpos = humr.Position + Vector3.new(0, hos, 0)
local campos = humrpos + Vector3.new(cd, cd, cd)
camera.CFrame += CFrame.new(campos, humrpos)
end
end
end
RunService:BindToRenderStep("isocam", Enum.RenderPriority.Camera.Value + 1, updcam)
if anyone has any solution or method on how to do this please let me know. I have been stuck on this for hours in the double digits but just cant seem to figure it out.
Do you mean that the X-axis rotation is relative to the camera itself? If so, here is the code:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local cd = 64
local hos = 2
local vertical = 0
camera.FieldOfView = 20
local function updcam()
local chr = player.Character
if chr then
local humr = chr:FindFirstChild("HumanoidRootPart")
if humr then
local humrpos = humr.Position + Vector3.new(0, hos, 0)
local campos = humrpos + Vector3.new(cd, cd, cd)
camera.CFrame = CFrame.new(campos, humrpos)
camera.CFrame = camera.CFrame *CFrame.Angles(vertical/10 ,0,0)
end
end
end
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
vertical -=1
elseif input.KeyCode == Enum.KeyCode.E then
vertical +=1
end
end)
RunService:BindToRenderStep("isocam", Enum.RenderPriority.Camera.Value + 1, updcam)
I made another If you wanna make it relative to humanoid
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local cd = 64
local hos = 2
local vertical = 0
local highest = nil
local lowest = nil
camera.FieldOfView = 20
local function updcam()
local chr = player.Character
if chr then
local humr = chr:FindFirstChild("HumanoidRootPart")
if humr then
local humrpos = humr.Position + Vector3.new(0, hos, 0)
local x,y,z = cd,cd,cd
local humrpos_to_camera =Vector3.new(x,y,z) -- vector3.new(cd,cd,cd) Make the Code easy to fix if you want make x,z different
local angleY = (math.atan2(z, x)-math.rad(90))
local angleX = (vertical/10)
if math.deg(angleX) < -40 then -- make sure camera dont go over the head
if highest == nil then
highest = vertical
end
vertical = highest
angleX = math.rad(-40)
end
if math.deg(angleX) > 30 then -- keep camera a distance from ground
if lowest == nil then
lowest = vertical
end
vertical = lowest
angleX = math.rad(30)
end
local first_rotation = CFrame.Angles(0,angleY,0):PointToWorldSpace(humrpos_to_camera) -- here look at z direction
local second_rontation = CFrame.Angles(angleX,0,0):PointToWorldSpace(first_rotation)
local third_rotation = CFrame.Angles(0,-angleY,0):PointToWorldSpace(second_rontation) -- turn it back
local campos = humrpos+third_rotation
camera.CFrame = CFrame.new(campos,humrpos)
end
end
end
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
vertical = vertical+1
elseif input.KeyCode == Enum.KeyCode.E then
vertical =vertical-1
end
end)
RunService:BindToRenderStep("isocam", Enum.RenderPriority.Camera.Value + 1, updcam)
I probably should’ve been a bit more specific, sorry about that.
Here’s my current camera https://gyazo.com/98eca3172410adea0638ddc9df013f02
but i wanna be able to rotate it with my mouse like this https://gyazo.com/3d4b98da64659efd7c3ba2695e5ee9ef
for some reason it’s not allowing me to rotate my camera only along the x axis, like i wanna 360 around the player but from the same angle if you know what i mean
Okay, so update I got it to semi work
I wanna be able to rotate like this all the way around
but it ends up doing this
Here’s the code
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local cd = 64
local cdx = 64
local hos = 2
local uis = game:GetService("UserInputService")
camera.FieldOfView = 20
local function updcam()
local chr = player.Character
if chr then
local humr = chr:FindFirstChild("HumanoidRootPart")
if humr then
local delta = uis:GetMouseDelta()
cdx = cdx + delta.X
local humrpos = humr.Position + Vector3.new(0, hos, 0)
local campos = humrpos + Vector3.new(cdx, cd, cd + delta.X)
camera.CFrame = CFrame.new(campos, humrpos)
end
end
end
RunService:BindToRenderStep("isocam", Enum.RenderPriority.Camera.Value + 1, updcam)
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local cd = 64
local cdx = 64
local hos = 2
local uis = game:GetService("UserInputService")
local total_x = 0
camera.FieldOfView = 20
local rotate = 0
local function updcam()
local chr = player.Character
if chr then
local humr = chr:FindFirstChild("HumanoidRootPart")
if humr then
local delta = uis:GetMouseDelta()
rotate = rotate - delta.X
local rotate_angle = CFrame.Angles(0, math.rad(rotate), 0)
local first_rotation = rotate_angle:VectorToWorldSpace(Vector3.new(cd,cd,cd))
--cdx = cdx+delta.X
local humrpos = humr.Position + Vector3.new(0, hos, 0)
local campos = humrpos + first_rotation
camera.CFrame = CFrame.new(campos, humrpos)
end
end
end
RunService:BindToRenderStep("isocam", Enum.RenderPriority.Camera.Value + 1, updcam)