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

Well that was a surprise, anyways can you make sure the other sections of code is not interfering with the aim function?

nope i printed toaim every time it gets called and it only prints when i press right click or reload and its the correct value

I meant other parts of the script calling .aim that might can cause some confusion from the scripts because I see module.aim being called from different parts of the code.

Edit: Just the confirm is the value a number value or an integer value?

its a integer that may be the issue, you don’t say which type of value so i assumed integer now its works

2 Likes

Part 3. Pls. I need my gun to switch and that’s a main mechanic to a fps game

2 Likes

If I understand correctly, can’t you just filter the viewmodel from the camera/mouse? That way you can aim down sights and shoot with recoil, without having the bullets fly into your own gun

Can you elaborate more on this sentence?

By Using Mouse.TargetFilter, and adding the player’s viewmodel to the filter, the mouse or whatever should ignore the viewmodel even when your aiming down sights. I haven’t actually read your guide but I think this is what your talking about

.TargetFilter only accepts one Instance, so if you want to blacklist multiple Instances, it would be a hassle to figure out.

I feel like it would be easier than making a mouse module, just use a folder or something

Well you could do that, but now you have random things cramped inside 1 folder and also sometimes you want to ignore everything inside something except for 1 thing.

So I’d prefer just making a simple mouse module. It’s a very flexible option.

please make uncopylocked place im suffering with all error and mess

Can you reply with the Spring Module script I can’t open that file type in studio or any other program

-- Constants

local ITERATIONS	= 8
local Spring = {}
Spring.__index = Spring

function Spring.new(self, mass, force, damping, speed)

	local spring	= setmetatable({
		Target		= Vector3.new();
		Position	= Vector3.new();
		Velocity	= Vector3.new();

		Mass		= mass or 5;
		Force		= force or 50;
		Damping		= damping or 4;
		Speed		= speed  or 4;
	}, Spring)
	return spring
end

function Spring.getstats(self)
	return self.Mass, self.Force, self.Damping, self.Speed
end

function Spring.changestats(self, mass, force, damping, speed)
	self.Mass = mass or self.Mass
	self.Force = force or self.Force
	self.Damping = damping or self.Damping
	self.Speed = speed or self.Speed
end

function Spring.shove(self, force)
	local x, y, z	= force.X, force.Y, force.Z
	if x ~= x or x == math.huge or x == -math.huge then
		x	= 0
	end
	if y ~= y or y == math.huge or y == -math.huge then
		y	= 0
	end
	if z ~= z or z == math.huge or z == -math.huge then
		z	= 0
	end
	self.Velocity	= self.Velocity + Vector3.new(x, y, z)
end

function Spring.update(self, dt)
	local scaledDeltaTime = dt * self.Speed / ITERATIONS
	for i = 1, ITERATIONS do
		local iterationForce= self.Target - self.Position
		local acceleration	= (iterationForce * self.Force) / self.Mass

		acceleration		= acceleration - self.Velocity * self.Damping

		self.Velocity	= self.Velocity + acceleration * scaledDeltaTime
		self.Position	= self.Position + self.Velocity * scaledDeltaTime
	end

	return self.Position
end

return Spring
1 Like

wow, that’s was actually realy useful dude, but, can you please make a third part of the tutorial? on the gun swap and reloading?, that would be amazing, but good work bro, you helped a lot of ppl

image

keep getting this error

code

local function GetBobbing(addition)
	return math.sin(tick() * addition * 1.3) * 0.5
end

function module.update(viewmodel,dt, RecoilSpring , BobbleSpring , SwayingSpring)
	viewmodel.HumanoidRootPart.CFrame = game.Workspace.Camera.CFrame
	
	local bobble = Vector3.new(GetBobbing(10) , GetBobbing(5) , GetBobbing(5))
	
	local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
	
	BobbleSpring:shove(bobble / 10 * (character.HumanoidRootPart.Velocity.Magnitude) / 10)
	
	local UpdatedRecoilSpring = RecoilSpring:update(dt)
	local UpdatedSwaySpring = RecoilSpring:update(dt)
	local UpdatedBobbleSpring = RecoilSpring:update(dt)
	
	viewmodel.HumanoidRootPart.CFrame = viewmodel.HumanoidRootPart.CFrame:ToWorldSpace(CFrame.new(UpdatedBobbleSpring.Y,UpdatedBobbleSpring.X , 0))
	
	viewmodel.HumanoidRootPart.CFrame *= CFrame.Angles(math.rad(UpdatedRecoilSpring.X)* 2,0,0)
	game.Workspace.Camera.CFrame *= CFrame.Angles(math.rad(UpdatedRecoilSpring.X),math.rad(UpdatedRecoilSpring.Y) , math.rad(UpdatedRecoilSpring.Z))
end

This error occurs when your player doesn’t load in fast enough. You can counter this by just adding
:WaitForChild().

i added a wait for child but is this supposed to happen?
https://gyazo.com/23f855c8d38b02a1c656ceffa5488d35

I think that is a recoil related issue, not sure though. It looks like one. If the :WaitForChild() is causing the issue then at the start of your code you can add if not game:IsLoaded() then game.Loaded:Wait() end.