Hi! So, using this tutorial, i made an Object Oriented Programming Isometric Camera for my game. The problem is that, since my game is isometric, the player’s camera will need to change angles sometimes so the Player can see what’s happening. What i did for this is i made a Folder with Models that contain two Hitboxes, one on the front side and the other on the back side. Once they’re touched by the Player, they should change the Player’s Camera’s angle to their Angle attribute. The problem here is that while the Player touching the Hitboxes is detected, the Camera doesn’t switch angles. I put a picture to better explain it.
Here’s the code:
Client:
--||Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--||Variables
local Classes = ReplicatedStorage:WaitForChild("Classes")
local IsometricCamera = require(Classes.IsometricCamera)
local CameraRotationM = require(Classes.CameraRotation)
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")
local Camera = workspace.Camera
local Sectors = workspace:WaitForChild("Sectors")
-------------------------
local IC = IsometricCamera.New(Camera, Character, Root, Humanoid)
IC:ConnectRenderStepped()
for _, Sector in ipairs(Sectors:GetChildren()) do
for _, CameraRotation in ipairs(Sector.CameraRotations:GetChildren()) do
local CR = CameraRotationM.New(CameraRotation)
end
end
IsometricCamera Module/Class:
export type IsometricCamera = {
_Camera: Camera,
_Character: Model,
_Root: BasePart,
_Humanoid: Humanoid
}
local IsometricCamera : IsometricCamera = {}
IsometricCamera.__index = IsometricCamera
--|Settings
local FOV = 1
local Zoom = .25 -- 100<Zoom<=1000 --Controls how zoomed in the camera is
local Distance = 80 * Zoom
local CamCFrameInfo = CFrame.new(0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, FOV)
local CamDistance = Distance
local Multiply = 0.7075 -- Line up multiple objects in a diagonal (default 0.7075)
local CamHeight = CamDistance * Multiply
local CamAngleOffset = 45 -- Angle offset in degrees for tilting the camera around the Y axis
-- Convert angle offset to radians for camera rotation
local AngleRadians = math.rad(CamAngleOffset)
function IsometricCamera.New(Camera: Camera, Character: Model, Root: BasePart, Humanoid: Humanoid)
local self = setmetatable({}, IsometricCamera)
self._Camera = Camera
self._Character = Character
self._Root = Root
self._Humanoid = Humanoid
return self
end
function IsometricCamera:Run()
self._Camera.CameraType = Enum.CameraType.Scriptable
self._Camera.CFrame *= CamCFrameInfo
end
function IsometricCamera:FollowCharacter()
if self._Character and self._Root then
-- Calculate the camera's position behind the character
local XOffset = math.sin(AngleRadians) * CamDistance
local ZOffset = math.cos(AngleRadians) * CamDistance
local CamPosition = self._Root.Position + Vector3.new(XOffset, CamHeight, ZOffset)
-- Set the camera's CFrame to follow the player, looking in a fixed direction
self._Camera.CFrame = CFrame.new(CamPosition, self._Root.Position)
end
end
function IsometricCamera:SwitchAngle(Angle: number)
print("Yay!")
CamAngleOffset = Angle
end
function IsometricCamera:ConnectRenderStepped()
game:GetService("RunService").RenderStepped:Connect(function()
self:Run()
self:FollowCharacter()
end)
end
return IsometricCamera
CameraRotation Module/Class:
export type CameraRotation = {
_Model: Model,
_IC: IsometricCamera.IsometricCamera
}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Classes = ReplicatedStorage:WaitForChild("Classes")
local IsometricCamera = require(Classes.IsometricCamera)
local CameraRotation : CameraRotation = {}
CameraRotation.__index = CameraRotation
function CameraRotation.New(Model: Model)
local self = setmetatable({}, CameraRotation)
self._Model = Model
self._Model.Front.Touched:Connect(function(Hit: BasePart)
local Player = Players:GetPlayerFromCharacter(Hit.Parent)
if Player then
self:Rotate(self._Model.Front:GetAttribute("Angle"))
end
end)
self._Model.Back.Touched:Connect(function(Hit: BasePart)
local Player = Players:GetPlayerFromCharacter(Hit.Parent)
if Player then
self:Rotate(self._Model.Back:GetAttribute("Angle"))
end
end)
return self
end
function CameraRotation:Rotate(Angle: number)
print("Works.")
IsometricCamera:SwitchAngle(Angle)
end
return CameraRotation