Project Zomboid camera?

Hello, i wanted to make a similar camera as in the game Project Zomboid and for most ive tried nothing works.

This is how its supposed to look like:


I’ve tried to do something but only got a top down one:

wait()
local Player = game:GetService("Players").LocalPlayer
local Character
local Humanoid
local Camera = workspace.CurrentCamera

local RunService = game:GetService("RunService")

local Dampening = 1000
local Power = 10000
local MaxForce = Vector3.new(4000, 4000, 4000)

function OnCharacterAdded(AddedCharacter)
	if AddedCharacter == nil then
		repeat wait() until AddedCharacter ~= nil
	end

	if AddedCharacter.Parent == nil then
		repeat wait() until AddedCharacter.Parent ~= nil
	end

	if AddedCharacter ~= nil and AddedCharacter.Parent ~= nil then
		Character = AddedCharacter
		Humanoid = Character:WaitForChild("Humanoid")

		Camera.CameraType = Enum.CameraType.Scriptable

		CreateCameraPositionPart()
		RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, UpdateCameraPosition)
	end
end

function UpdateCameraPosition()
	Character.CameraPositionPart.BodyPosition.Position = Character.PrimaryPart.Position + Vector3.new(-1, 50, 0)
	Camera.CFrame = CFrame.new(Character.CameraPositionPart.Position, Character.CameraPositionPart.Position - Vector3.new(-1, 50, 0))
end

function CreateCameraPositionPart()
	local CameraPositionPart = Instance.new("Part")
	CameraPositionPart.CanCollide = false
	CameraPositionPart.Transparency = 1
	CameraPositionPart.Name = "CameraPositionPart"
	CameraPositionPart.Parent = Character

	local CameraBodyPosition = Instance.new("BodyPosition")
	CameraBodyPosition.D = Dampening
	CameraBodyPosition.P = Power
	CameraBodyPosition.MaxForce = MaxForce
	CameraBodyPosition.Parent = CameraPositionPart

	return
end

Player.CharacterAdded:Connect(OnCharacterAdded)

Any ideas?

You’re probably looking for something called an isometric camera. I’ve found a really easy to understand guide to create one.
https://create.roblox.com/docs/tutorials/scripting/input-and-camera/controlling-the-users-camera#creating-an-isometric-camera

You basically have to add the same amount of distance from the primary part (the root of the character) to X, Y, Z and then use the CFrame.lookAt function

Camera.CFrame = CFrame.lookAt(cameraPosition, rootPosition)

Remember to change the variables because I’m not really sure how you set their names. Hope this helps!

Thank you! It works but i wanted to implement a thingy where if the player touches a part it makes the fov zoom in abit, and for some reason its impossible to do. Atleast for me.

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera

local CAMERA_DEPTH_DEFAULT = 130
local CAMERA_DEPTH_TOUCHED = 65
local HEIGHT_OFFSET = 2

local partName = "c_inside_x"

camera.FieldOfView = 20

local function updateCamera()
	local character = player.Character
	if character then
		local root = character:FindFirstChild("HumanoidRootPart")
		if root then
			local rootPosition = root.Position + Vector3.new(0, HEIGHT_OFFSET, 0)

			-- Check if the part is touched
			local ray = Ray.new(rootPosition, Vector3.new(CAMERA_DEPTH_DEFAULT, CAMERA_DEPTH_DEFAULT, CAMERA_DEPTH_DEFAULT).unit * CAMERA_DEPTH_DEFAULT)
			local hit, hitPosition, hitNormal = workspace:FindPartOnRayWithIgnoreList(ray, {character})

			-- Update camera depth based on the presence of the part
			local cameraDepth = hit and hit.Name == partName and CAMERA_DEPTH_TOUCHED or CAMERA_DEPTH_DEFAULT

			local cameraPosition = rootPosition + Vector3.new(cameraDepth, cameraDepth, cameraDepth)
			camera.CFrame = CFrame.lookAt(cameraPosition, rootPosition)
		end
	end
end

RunService:BindToRenderStep("IsometricCamera", Enum.RenderPriority.Camera.Value + 1, updateCamera)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.