So a week ago I wrote this simple VM code because I wanted to experiment with FPS type assets however, as seen in the video the viewmodel seems to be pretty snappy and I need it to be smoothly welded to the players camera.
here is my code:
local vem = "VEM"
script.Parent.Equipped:Connect(function()
local viewmodel = game.ReplicatedStorage.VM:Clone()
viewmodel.Parent = workspace.Camera
local weapon = game.ReplicatedStorage.Models[script.Parent.Name]:Clone()
weapon.Parent = viewmodel
local char = viewmodel:WaitForChild("Torso")
local M6D = Instance.new("Motor6D", char)
M6D.Name = "ToolGrip"
char.ToolGrip.Part0 = char
char.ToolGrip.Part1 = viewmodel[script.Parent.Name].BodyAttach
local limbs = viewmodel:GetDescendants()
for i,v in pairs(limbs)do
if v:IsA("BasePart")then do
PhysicsService:SetPartCollisionGroup(v, vem)
end
end
end
local humanoid = viewmodel:WaitForChild('Humanoid')
local Id = humanoid:LoadAnimation(viewmodel[script.Parent.Name]:WaitForChild('Hold'))
Id:Play()
game:GetService("RunService").Stepped:Connect(function()
viewmodel.Head.CFrame = workspace.CurrentCamera.CFrame
end)
end)
local PhysicsService = game:GetService("PhysicsService")
local vem = "VEM"
script.Parent.Equipped:Connect(function()
local viewmodel = game.ReplicatedStorage.VM:Clone()
viewmodel.Parent = workspace.Camera
local weapon = game.ReplicatedStorage.Models[script.Parent.Name]:Clone()
weapon.Parent = viewmodel
game:GetService("RunService").Stepped:Connect(function()
local char = viewmodel:WaitForChild("Torso")
local M6D = Instance.new("Motor6D", char)
M6D.Name = "ToolGrip"
char.ToolGrip.Part0 = char
char.ToolGrip.Part1 = viewmodel[script.Parent.Name].BodyAttach
local limbs = viewmodel:GetDescendants()
for i,v in pairs(limbs)do
if v:IsA("BasePart")then do
PhysicsService:SetPartCollisionGroup(v, vem)
end
end
end
local humanoid = viewmodel:WaitForChild('Humanoid')
local Id = humanoid:LoadAnimation(viewmodel[script.Parent.Name]:WaitForChild('Hold'))
Id:Play()
viewmodel.Head.CFrame = workspace.CurrentCamera.CFrame
end)
end)