Hey guys, thanks for reading.
I’ve been following the EgoMoose FPS tutorial (here’s the link: The First Person Element Of A First Person Shooter - Scripting Helpers) and I’m stuck on the part where he make the View Models arms stick to the gun. I am trying to create my own FPS engine with this as a base.
This is his script:
local function updateArm(key)
-- get shoulder we are rotating
local shoulder = viewModel[key.."UpperArm"][key.."Shoulder"];
-- calculate worldspace arm cframe from Right or Left part in the weapon model
local cf = weapon[key].CFrame * CFrame.Angles(math.pi/2, 0, 0) * CFrame.new(0, 1.5, 0);
-- update the C1 value needed to for the arm to be at cf (do this by rearranging the joint equality from before)
shoulder.C1 = cf:inverse() * shoulder.Part0.CFrame * shoulder.C0;
end
local function onUpdate(dt)
viewModel.Head.CFrame = camera.CFrame;
-- update every frame so the arms stay in place when the player aims down sights
updateArm("Right");
updateArm("Left");
end
--(Somewhere in his tutorial he links onUpdate to RenderStepped, Mine is just shorter)
--This is my script:
local function armPosition()
local cf = gunModelinUse.Right.CFrame * CFrame.Angles(math.pi/2,0,0) * CFrame.new(0,1.5,0)
shoulder.C1 = cf:Inverse() * shoulder.Part0.CFrame * shoulder.C0
local cf2 = gunModelinUse.Left.CFrame * CFrame.Angles(math.pi/2,0,0) * CFrame.new(0,1.5,0)
lshoulder.C1 = cf:Inverse() * lshoulder.Part0.CFrame * lshoulder.C0
end
game:GetService("RunService").RenderStepped:Connect(function()
armPosition()
end)```
I would provide screenshots but there is nothing to screenshot. My arm just flings away when you equip it, and I have no idea why.
Thanks, Have a great day ![]()