The character cannot keep up with the camera when rotating the camera quickly.
How to solve this problem?
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local function showParts()
for _,v in character:GetChildren() do
if v:IsA("BasePart") and v.Name ~= "Head" then
v.LocalTransparencyModifier = 0
end
end
end
RunService.RenderStepped:Connect(function(deltaTime: number)
showParts()
character.Humanoid.CameraOffset = Vector3.new(0,0,-1)
end)
This is caused by setting your humanoidoffset. If you want to fix this effect then we would have to set the offset by cameras CFrame.
So what you could try is turn off autorotate in the humanoid properties.
Then get the cameras Y rotation then apply it to the humanoidrootpart in Runservice.
Now setting the cameras offset is gonna look goofy when looking up and down so we would have to get the dot product from -1 and 1.
--//[[ Services ]]\\--
local players = game:GetService("Players")
local runservice = game:GetService("RunService")
local camera = game:GetService("Workspace").CurrentCamera
--//[[ Character Variables ]]\\--
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart") :: Part
local humanoid = character:WaitForChild("Humanoid") :: Humanoid
humanoid.AutoRotate = false -- Makes it not rotate when moving
--//[[ View Character in FirstPerson ]]\\--
local function Viewbody()
for index, child in character:GetChildren() do
if child:IsA("BasePart") and not string.match(child.Name, "Head") then
child.LocalTransparencyModifier = 0
end
end
end
--//[[ SetCamera Offset ]]\\--
local function UpdateCamera(delta)
local upvector = camera.CFrame.LookVector:Dot(Vector3.new(0, 1, 0)) -- Gives us -1 and 1 when looking up and down
local rx, ry, rz = camera.CFrame:ToOrientation()
local YLook = math.abs(math.clamp(upvector, -1, 0))
local ZLook = math.abs(math.clamp(upvector, -1, -.3)) / 1.5
camera.CFrame = camera.CFrame *
CFrame.new(0, YLook, -ZLook)
humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position) *
CFrame.Angles(0, ry, 0) -- Set the rotation to cameras rotation
end
--//[[ Updates Both Functions ]]\\--
local function UpdateService(delta: number)
Viewbody()
UpdateCamera(delta)
end
--//[[ Connections ]]\\--
runservice.RenderStepped:Connect(UpdateService)
Thanks for the code! I learned a lot from your code, although it doesn’t solve the problem of not being able to sync. Finally I solved it using RunService.HeartBeat and Enum.CameraType.Scriptable