#Isometric Camera problem

1 messages · Page 1 of 1 (latest)

humble bramble
#

So i have an isometric camera script but it seems to not work when im behing objects, the raycast doesnt detect objects when im still and my camera jumps everywhere

local zoom = script:GetAttribute('Zoom')
local FOV = script:GetAttribute("FOV")
local UIS = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = workspace.CurrentCamera
local HighLight = Character:WaitForChild("Torso"):WaitForChild("Highlight")
local HumanoidRoot = Character:WaitForChild("HumanoidRootPart")

Camera.CameraType = Enum.CameraType.Custom

local RunService = game:GetService("RunService")

local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = {Character}
RayParams.FilterType = Enum.RaycastFilterType.Exclude

local function createDebugRay(startPos, endPos)
    local distance = (endPos - startPos).Magnitude
    local part = Instance.new("Part")
    part.Anchored = true
    part.CanCollide = false
    part.CanQuery = false
    part.Material = Enum.Material.Neon
    part.Color = Color3.fromRGB(0, 255, 0)
    part.Size = Vector3.new(0.05, 0.05, distance)
    part.CFrame = CFrame.new(startPos, endPos) * CFrame.new(0, 0, -distance / 2)
    part.Parent = workspace
    game.Debris:AddItem(part, 6)
end

local normalFov = Camera.FieldOfView
local icoEnabled = false

UIS.InputBegan:Connect(function(inpt,gm)
    if inpt.KeyCode == Enum.KeyCode.V then
        icoEnabled = not icoEnabled
        Camera.FieldOfView = normalFov
    end
end)
#

RunService.RenderStepped:Connect(function()
    if not icoEnabled then return end
    zoom = script:GetAttribute('Zoom')
    FOV = script:GetAttribute("FOV")
    Camera.FieldOfView = FOV
    if Character then
        if Character:FindFirstChild('Head') then
            local HeadPart = Character.Head
            game:GetService('SoundService'):SetListener(Enum.ListenerType.ObjectPosition, HumanoidRoot)
            local HPos = Character.Head.Position
            
            local MH = Mouse.Hit.Position
            local mag = (HPos - MH).Magnitude
            
            if mag <= script:GetAttribute('Div') then
                local g = {CFrame = CFrame.new(Vector3.new(HPos.X+zoom, HPos.Y+zoom, HPos.Z+zoom), MH)}
                game.TweenService:Create(Camera, TweenInfo.new(0,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out), g):Play()
                print(mag)
            end
            
            local direction = HumanoidRoot.Position - Camera.CFrame.Position
            local rayResult = workspace:Raycast(Camera.CFrame.Position, direction, RayParams)
            print(rayResult)
            
            if rayResult and rayResult.Instance then
                HighLight.Enabled = true
                createDebugRay(Camera.CFrame.Position, rayResult.Position)
            end
            if not rayResult then
                HighLight.Enabled = false
                print("not Found")
                createDebugRay(Camera.CFrame.Position, HPos)
                print(workspace.CurrentCamera.CFrame)
            end
        end
    end
    game["Run Service"].RenderStepped:Wait()
end)
 

#

Isometric Camera problem

fiery lark
#

bruh

#

bruh

fiery lark
#

your math is wrong somewhere. consider the fact that you have local direction = HumanoidRoot.Position - Camera.CFrame.Position then consider the fact the result position of the camera is dependent upon the camera's position.

#

you've created a feedback loop somewhere

#

try taking beginner debugging steps like.. add a print() to show what code is running and when.