So, i was making a viewmodel script that transforms it to Neck position and torso+camera X rotation. And when i launch it, it looks something like this: https://gyazo.com/e21665257bd41e6ce2a5f61ed05ed433.
When you move camera really fast, it lags behind. Im pretty sure its because of *Cframe.Angles() in the script and it takes time to procedure/render it, so im asking for help to find the solution. Here is the script
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local head = character:FindFirstChild("Head") or character:WaitForChild("Head")
local torso = character:FindFirstChild("Torso") or character:WaitForChild("Torso")
local viewmodel = game.ReplicatedStorage.viewmodel_3rd_person
local colors = character:WaitForChild("Body Colors")
local shirt = character:WaitForChild("Shirt")
local cgun
local decrease = 1.2
if colors then colors:Clone().Parent = viewmodel end
if shirt then shirt:Clone().Parent = viewmodel end
repeat wait() until game:IsLoaded()
for i,v in pairs(character:GetChildren()) do
if v:IsA("CharacterMesh") then
--print("found mesh")
print(v.BodyPart)
if v.BodyPart == Enum.BodyPart.LeftArm or v.BodyPart == Enum.BodyPart.RightArm then
--print("mesh belongs to arm")
v:Clone().Parent = viewmodel
end
end
end
script.EquipGun.Event:Connect(function(gun : Model, anim : string)
script.ShowViewmodel.Value = true
local clone = gun
local handle = gun:FindFirstChild("Handle")
handle.Anchored = false
local grip = viewmodel["Right Arm"].Grip
--clone.Parent = viewmodel
local weld = Instance.new("Weld",viewmodel)
weld.Part0 = handle
weld.Part1 = grip
--weld.Enabled = true
--handle.CFrame = grip.CFrame
--print(handle.CFrame)
--cgun = gun
--print(viewmodel["Right Arm"].Grip.WorldCFrame)
end)
--Enum.RenderPriority.Camera.Value = 1
game:GetService("RunService"):BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, function(deltaTime)--game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
local show = script.ShowViewmodel.Value
local x,y,z = game.Workspace.CurrentCamera.CFrame:ToOrientation()
viewmodel.HumanoidRootPart.CFrame = torso.NeckAttachment.WorldCFrame
viewmodel.HumanoidRootPart.CFrame*=CFrame.Angles(x/decrease,0,0)
if show then
viewmodel.Parent = workspace
--viewmodel.HumanoidRootPart.CFrame = CFrame.new(torso.NeckAttachment.WorldPosition
-- +Vector3.new(0,0.1,0))
--* CFrame.Angles(x,0,0) --game.Workspace.CurrentCamera.CFrame.Rotation
local lh = character:FindFirstChild("Left Arm")
local rh = character:FindFirstChild("Right Arm")
--[[if cgun then
cgun.Handle.CFrame = viewmodel["Right Arm"].Grip.CFrame
end]]
if lh and rh then
lh.LocalTransparencyModifier = 1
rh.LocalTransparencyModifier = 1
print("disabled transparency")
end
else
viewmodel.Parent = game.ReplicatedStorage
local lh = character:FindFirstChild("Left Arm")
local rh = character:FindFirstChild("Right Arm")
if lh and rh then
lh.LocalTransparencyModifier = 0
rh.LocalTransparencyModifier = 0
print("disabled transparency")
end
end
end)