I’m learning how to create a viewmodel and understand the idea, but the issue is that it doesn’t face forwards due to the CFrame. Adjusting the orientation causes glitches as well.
Changing orientation outside of CFrame causes glitches as seen in the video. I don’t know of any alternatives, should I avoid using the camera?
LocalScript inside StarterGUI
local viewmodel = game:GetService("ReplicatedStorage"):WaitForChild("Viewmodel"):Clone()
viewmodel.Parent = workspace
local viewmodelparts = viewmodel:GetChildren()
local camera = workspace.CurrentCamera
local camcframe = camera.CFrame
local plr = game:GetService("Players").LocalPlayer
local event = game:GetService("ReplicatedStorage"):WaitForChild("viewmodel_event")
camera:GetPropertyChangedSignal("CFrame"):Connect(function() -- detect when the camera moves
if camera.CFrame ~= camcframe then
game:GetService("TweenService"):Create(viewmodel.PrimaryPart, TweenInfo.new(0.1, Enum.EasingStyle.Sine), { CFrame = camcframe + Vector3.new(0, -1.4, 0) }):Play() -- lag viewmodel behind
game:GetService("TweenService"):Create(viewmodel.PrimaryPart, TweenInfo.new(0.1, Enum.EasingStyle.Sine), { Orientation = Vector3.new(camera.Focus) }):Play()
camcframe = camera.CFrame -- set camcframe to new cframe
else
return -- if it didn't move return
end
end)
event.OnClientEvent:Connect(function(arm, action) -- viewmodel animation event
local selected = viewmodel:WaitForChild(arm.."Arm"):GetChildren() -- find the select arm
for i, v in pairs(selected) do -- make selected arm visible
if v:IsA("MeshPart") then
v.Transparency = 0
end
end
if action == "item" then -- check what the action is (item is only action)
local animator = viewmodel:WaitForChild("Humanoid"):WaitForChild("Animator")
local grabanim = Instance.new("Animation")
grabanim.AnimationId = "rbxassetid://12602387442"
local grabtrack = animator:LoadAnimation(grabanim)
grabtrack:Play()
print("playing anim")
-- finish this part later
else
return -- if it's none of the actions return
end
end)