Please take a look at my code:
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local viewModel = Instance.new("Part")
local viewModelStorage = game.Workspace:WaitForChild("storages"):WaitForChild("client"):WaitForChild("viewModels")
viewModel.Transparency = 1
viewModel.CanCollide = false
viewModel.Name = "head"
viewModelStorage:ClearAllChildren()
viewModel.Parent = viewModelStorage
viewModel.Anchored = true
function _wait(seconds)
local Heartbeat = RunService.Heartbeat
local StartTime = tick()
repeat Heartbeat:Wait() until tick() - StartTime >= seconds
end
local lastRotation = CFrame.Angles(0, 0, 0)
local latency = 0.05
while true do
RunService.RenderStepped:Wait()
local camCframe = camera.CFrame
local camPosition = camCframe.Position
local camRotation = camCframe - camPosition
local magnitude = (camRotation.LookVector - lastRotation.LookVector).Magnitude
viewModel.CFrame = CFrame.new(camPosition) * lastRotation
TweenService:Create(
viewModel,
TweenInfo.new(
latency,
Enum.EasingStyle.Linear
),
{
["CFrame"] = camCframe
}
):Play()
lastRotation = camRotation
end
I have a part welded to the ViewModel as it can be seen here:
The goal here is to have the viewModel
in the correct position without any latency, however, I want the rotation to have latency, just like Minecraft:
To a certain extent, it works. However, it jitters badly:
So how do I stop it from jittering badly as shown in the gif above?
For context, visit the last post about this: https://devforum.roblox.com/t/is-math-rad-having-a-presision-error/877090