Designing an FPS Framework: Beginner’s guide [PART 2]

Already asked by someone else,

So, to do that you can do , i know there more andvanced way to do it but huh

script.Parent.Equipped:Connect(function()
    game["Run Service"]:BindToRenderStep("view_Model_render", Enum.RenderPriority.Camera.Value +1, function(dt)
        --view model update function here such as Viewmodel.Primary.CFrame = workspace.CurrentCamera.CFrame
    end)
    
    
    script.Parent.Unequipped:Connect(function()
        game["Run Service"]:UnbindFromRenderStep("view_Model_render");
        workspace.CurrentCamera.Viewmodel:Destroy()
    end)
    
end)
1 Like

If anyone is having problems with aim not tweening and the aimalpha just snapping from 0 to 1, I had the same problem and switched to a numbervalue instead of int and it worked

hello! could you please tell me what colors are your script editor color codes (text, background,…etc) please?, they look very good :}

1 Like

Sorry for the inconvenience, however, the swaying is not working for me. It does not throw any errors or warnings. It simply changes the walking animation:

I’m unsure what I could be doing wrong, as I have been comparing my script to yours for quite a while now.

My update func:

function module.update(viewmodel, dt, recoilSpring, bobbleSpring, swayingSpring, currentModel)
	viewmodel.CameraBone.CFrame = game.Workspace.CurrentCamera.CFrame
	
	local aimPart = currentModel:FindFirstChild("AimPart")
	
	local bobble = Vector3.new(getBobbing(10), getBobbing(5), getBobbing(5))
	local mouseDelta = UIS:GetMouseDelta()
	
	local character = players.LocalPlayer.Character or players.LocalPlayer.CharacterAdded:Wait()
	
	bobbleSpring:shove(bobble / 10 * (character.HumanoidRootPart.Velocity.Magnitude) / 10)
	swayingSpring:shove(Vector3.new(-mouseDelta.X / 500, mouseDelta.Y / 200, 0))
	
	local updatedRecoilSpring = recoilSpring:update(dt)
	local updatedBobbleSpring = bobbleSpring:update(dt)
	local updatedSwaySpring = bobbleSpring:update(dt)
	
	aimPart.CFrame = aimPart.CFrame:Lerp(viewmodel.CameraBone.CFrame, game.ReplicatedStorage.SWATSys.Values.AimAlpha.Value)
	
	viewmodel.CameraBone.CFrame = viewmodel.CameraBone.CFrame:ToWorldSpace(CFrame.new(updatedBobbleSpring.Y, updatedBobbleSpring.X, 0))
	viewmodel.CameraBone.CFrame *= CFrame.new(updatedSwaySpring.X, updatedSwaySpring.Y, 0)
	
	viewmodel.CameraBone.CFrame *= CFrame.Angles(math.rad(updatedRecoilSpring.X) * 2, 0, 0)
	game.Workspace.CurrentCamera.CFrame *= CFrame.Angles(math.rad(updatedRecoilSpring.X), math.rad(updatedRecoilSpring.Y), math.rad(updatedRecoilSpring.Z))
end

Thanks in advance,
Fizzitix

1 Like

Its not actually studio, I’m using VSCode

1 Like

In the video you’re not swinging your camera around to show the sway, so I don’t really know how I would help you.

Nothing happens when I swing my camera around. I was walking to show how the sway changes the walking animation, and doesn’t do what its supposed to do.

Edit so I don’t have to reply: God, that was dumb, can’t believe I didn’t see that lmao. Thanks a lot!

image

1 Like

I am having trouble here. Where do i put this line of script? nevermind, figured it out myself

can someone please give me the link to the exact spring module(the file isnt working for me)

Hey, I have a question, how do i make the bobbing faster?

increase the addition parameter

Is it possible that we can get a tutorial on view model collisions? Like where it pushes back when you walk up to a wall.

mb i forgot to reply to this one. well i dont play on making one in the near future. if there is it probably wouldnt be apart of this tutorial (ie not a part 3). but if you are looking forward to making one, there are multiple ways.

  1. cast a ray from the head to some distance where it matches the barrel’s Z position (relative to the head), and if the ray detects something move the viewmodel back depending on the offset.

  2. cast a ray from the barrel of the gun to some distance, if the ray detects something move the viewmodel back depending on the offset

Somethings to add:

Make it serversided, so all players are able to see whats going on…

Maybe make it tool based, so different tool equipped means yknow.

thats gonna be heavy on the server bro

hello so uhm whenever someone dies the arms just disappear when you respawn, and the old ones stay where you where before death. after the game yields because groza isnt in replicated storage

EDIT I FOUND THE REASON:
last tutorial you said startercharacter works too. just realized it kills the character meaning the script resets and cant find a viewmodel
if this happens to anyone move the script to starterplayerscripts:)