#how do i make the camera follow the player head

1 messages · Page 1 of 1 (latest)

indigo apex
#

local player = game.Players.LocalPlayer
local char = player.Character
local RunService = game:GetService("RunService")

char.Humanoid.CameraOffset = Vector3.new(0, 0, -1)

for i, v in pairs(char:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "Head" then

    v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
        v.LocalTransparencyModifier = v.Transparency
    end)

    v.LocalTransparencyModifier = v.Transparency

end

end

RunService.RenderStepped:Connect(function(step)
local ray = Ray.new(char.Head.Position, ((char.Head.CFrame + char.Head.CFrame.LookVector * 2) - char.Head.Position).Position.Unit)
local ignoreList = char:GetChildren()

local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)

if hit then
    char.Humanoid.CameraOffset = Vector3.new(0, 0, -(char.Head.Position - pos).magnitude)
else
    char.Humanoid.CameraOffset = Vector3.new(0, -0.5, -1.1)
end

end)

last sunBOT
#

studio** You are now Level 1! **studio

shy leaf
#

where your camera moves with your torso or head

indigo apex
#

kinda so like im tryna make a first person game

#

and

#

i have a slide mechanic and the head stays in the same spot

shy leaf
#

hmm

#

you could lower the viewmodel

#

so it seems like the player is closer to the ground

indigo apex
#

let me like explain it better

#

so i want a fp rougelike with like ultra kill doom movement and like the camera just stays locked in place

#

and i want it to follow where my animations go yknow what i mean

shy leaf
#

I see

last sunBOT
#

studio** You are now Level 14! **studio

shy leaf
#

change the position of the viewmodel and make it so its always near your head

#

instead of cameraoffset

indigo apex
#

and how would i do that?

#

srry im new to scripting

#

like ik basics but beyond that im clueless

shy leaf
#

so basically, what you would do is use runservice

#

and make is so the viewmodel is always at the head using cframe

#

lets say

Runservice.RenderStepped(function() 
  viewmodel:PivotTo(CFrame.lookat(Character.Head.Position, (Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-1)).Position)
end)```
#

The syntax might not be perfecgt

#

but I think you get the point

#

you could also add a slight offset in the viewmodel's position

#

so its not just stuck to the head

#

You might also want to change the direction which its looking at

#

Like I hope you get the basic idea

indigo apex
#

so instead of this
if hit then
char.Humanoid.CameraOffset = Vector3.new(0, 0, -(char.Head.Position - pos).magnitude)
else
char.Humanoid.CameraOffset = Vector3.new(0, -0.5, -1.1)
end

#

i use that

#

?

shy leaf
#

yes something like that, I ain't the most experienced with fps systems so please take this with a grain of salt

#

you might also want to do this

#
Runservice.RenderStepped(function()
  --make the viewmodel look towards camera lookvector
  viewmodel:PivotTo(CFrame.lookat(Character.Head.Position, (Camera.CFrame * CFrame.new(0,0,-1)).Position)
end)
indigo apex
#

Could i make it like when i hold ctrl it changes and stops when the animation stops?

shy leaf
#

just know that the primary part of the viewmodel won't be able to move