How to make the camera follow the player but player can’t move the camera

I haven’t been able to find an actual helpful post about this and yes I’ve looked around for solutions.

What’s happening is the player falls and once the HumanoidStateType changes to falling (the detection of the new hum state works) it’s supposed to freeze the camera in a way. What I mean by this is the camera is supposed to follow the player like it would normally, but prevent you from moving your camera at all.

1 Like
  1. Set camera.CameraType to Enum.CameraType.Scriptable
  2. Calculate offset between camera world position and player’s character (cam.Position - char.PrimaryPart.Position)
  3. Use a while loop with RunService.RenderStepped:Wait() and summ the character position with the offset (cam.Position = char.PrimaryPart.Position + Offset)
1 Like

Thanks for this but I feel like I kind of need an example script

You can’t ask for scripts on scripting support, you can only get help with scripts you have.
That meaning, you may need to try and understand what @g1mmethemoney said and put that into a script. If that doesn’t work, you can ask for help with the script you made.

I’m not too skilled with using the camera but I have something.

local XAngle = 0
local YAngle = 0
local CameraPosition = Vector3.new(Camera.CFrame.Position)
local Head = Character:FindFirstChild("Head")
local StartCFrame = CFrame.new((Head.CFrame.Position + Vector3.new(0, 2, 0))) * CFrame.Angles(0, math.rad(XAngle), 0) * CFrame.Angles(math.rad(YAngle), 0, 0)
local CameraCFrame = StartCFrame + StartCFrame:VectorToWorldSpace(Vector3.new(CameraPosition.X, CameraPosition.Y, CameraPosition.Z))
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new(CameraCFrame.Position)

This is what I came up with and it doesn’t work at all! :neutral_face:

If anyone has any solutions, please let me know!

So I’ve done something similar here is my code. make sure to change the camera to scriptable.
function FocusNPC()
goal=CFrame.new(Vector3.new(Root.CFrame),Vector3.new(target.Parent.Head.CFrame))
–local goal
Camera.CFrame = Camera.CFrame:Lerp(goal, .0333)

end

This can be achieved by checking the HumanoidState of the player and see if they’re falling!

Here’s my approach

Example

local RunService = game:GetService("RunService")

local function updateCamera()
    local player = game.Players.LocalPlayer
    local character = player.Character
    if not character then return end
    
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if not humanoid then return end
    
    if humanoid:GetState() == Enum.HumanoidStateType.Falling then
        -- Freeze camera movement
        local camera = workspace.CurrentCamera
        camera.CameraType = Enum.CameraType.Scriptable
        camera.CameraSubject = nil
    else
        -- Update camera position and orientation
        local camera = workspace.CurrentCamera
        local head = character:FindFirstChild("Head")
        if not head then return end
        
        local xAngle = 0 -- Modify as needed
        local yAngle = 0 -- Modify as needed
        local cameraPosition = Vector3.new(0, 2, -5) -- Modify as needed
        
        local startCFrame = CFrame.new(head.Position + Vector3.new(0, 2, 0))
        local cameraCFrame = startCFrame * CFrame.Angles(math.rad(xAngle), math.rad(yAngle), 0) * CFrame.new(cameraPosition)
        
        camera.CameraType = Enum.CameraType.Custom
        camera.CameraSubject = head
        camera.CFrame = cameraCFrame
    end
end

RunService.RenderStepped:Connect(updateCamera)

In my example, the updateCamera() function is called on every render step, which is about 60 times per second. Inside the function, we check if the player is falling and freezes the camera movement by setting the CameraType to Scriptable and clearing the CameraSubject. Otherwise, it’ll update the camera’s CFrame and restores the CameraType to Custom and sets the CameraSubject to the player’s head.

All settings are configurable and bound to testing to your needs.

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