Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why Is my character not visible when locked on a target?

Asked by 2 years ago

So I am writing this 3rd person camera script for my game and wan't it to have a lock on target feature for boss fights etc etc... I got it working but the thing is: when you go around the target your player is not vissible... Can someone please help me cause I am going crazy...

Here is my scipt:

local cameraLocked = true

local enemy = workspace.StarterCharacter.HumanoidRootPart


local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Camera = workspace.Camera
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local CameraAngleX, CameraAngleY = 0,0
local CameraCFrame,CameraFocus,StartCFrame
local CameraOffset = Vector3.new(1,3,9.5)
local Movement = Enum.UserInputType.MouseMovement
RunService.RenderStepped:Connect(function()
    if cameraLocked == false then
        if Camera.CameraType ~= Enum.CameraType.Scriptable then
            Camera.CameraType = Enum.CameraType.Scriptable
        end
        StartCFrame = CFrame.new((HumanoidRootPart.CFrame.Position)) * CFrame.Angles(0, math.rad(CameraAngleX), 0) *  CFrame.Angles(math.rad(CameraAngleY), 0, 0)
        CameraCFrame = StartCFrame:ToWorldSpace(CFrame.new(CameraOffset.X, CameraOffset.Y, CameraOffset.Z))
        CameraFocus = StartCFrame:ToWorldSpace(CFrame.new(CameraOffset.X, CameraOffset.Y, -10000))
        Camera.CFrame = CFrame.new(CameraCFrame.Position, CameraFocus.Position)
    else
        if Camera.CameraType ~= Enum.CameraType.Scriptable then
            Camera.CameraType = Enum.CameraType.Scriptable
        end
        StartCFrame = CFrame.new((HumanoidRootPart.CFrame.Position)) * CFrame.Angles(0, math.rad(CameraAngleX), 0) *  CFrame.Angles(math.rad(CameraAngleY), 0, 0)
        CameraCFrame = StartCFrame:ToWorldSpace(CFrame.new(0, 5, 9.5))
        CameraFocus = StartCFrame:ToWorldSpace(CFrame.new(CameraOffset.X, CameraOffset.Y, -10000))
        Camera.CFrame = CFrame.new(CameraCFrame.Position, enemy.Position)
    end
end)
UserInputService.InputBegan:Connect(function(InputObject)
    if cameraLocked == false then
        local UserInputType = InputObject.UserInputType
        if UserInputService.MouseBehavior ~= Enum.MouseBehavior.LockCenter then
            UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
        end
    end
end)
UserInputService.InputChanged:Connect(function(InputOject)
    if cameraLocked == false then
        local UserInputType= InputOject.UserInputType
        if(UserInputType== Movement)then
            local Delta = InputOject.Delta
            CameraAngleX = CameraAngleX-Delta.X
            CameraAngleY = math.clamp(CameraAngleY-Delta.Y, -75, 75)
        end
    else
    end
end)

Thanks

1 answer

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
2 years ago

The player is visible but its just out side of your view

Ad

Answer this question