Designing an FPS Framework: Beginner's guide

The Motor6D of C0 is the offset for Part0. Inversing the CFrame is also the same like doing ToWorldSpace. It’s something similar to that. We’re inversing because when we apply a Motor6D the Part1 would reposition itself and we need to offset the C0 to fix it.

2 Likes

I can’t download the ViewModel… Can you make it into a free model?

Sure thing. I’m not the original creator of this viewmodel though.

1 Like

Can you please explain more when you say :Inverse() is like ToWorldSpace()? I dont see the comparison. Also :Inverse() switches all the numbers in a CFrame’s positive and negative signs around. Positive numbers becoming negative and negative numbers becoming positive.

(Correct me if I’m wrong) So from my understanding, you set the part0 and part1 in the Motor6D, what this does is moves part1 to part0 position by default, then you have to use offset property C0 to fix it, but then wouldn’t you have to offset C1 instead? Because isn’t that the brick that is repositioning itself? (thanks for your help :grinning:)

Has anyone ever just used a viewport frame?
Wouldn’t that be much easier?

Sure you will need to calculate the light direction. But isn’t it much simpler to use? No need for messy formula, motor6d and welds. Just a simple view model and localscript.

Plus the gun will not clip through walls.

for some reason in This function:> function module.weldgun(gun)

local Main = gun.GunComponets.Handle

for i, v in ipairs(gun:GetDescendants()) do
if v:IsA(“BasePart”) and v ~= Main then
local NewMotor Instance.new(“Motor6D”)
NewMotor.Name = v.Name
NewMotor.Part0 = Main
NewMotor.Part1 = v
NewMotor.C0 = NewMotor.Part0.CFrame:inverse() * NewMotor.Part1.CFrame
NewMotor.parent = Main
end
end
end

it says in the newmotor.name = v.name line “ReplicatedSTorage.MainModule:13: attempt to index nil iwth ‘Name’”

my gun doesnt appear in my face.

local:
local gunmodel = game.ReplicatedStorage:WaitForChild(“Groza”)
local viewmodel = game.ReplicatedStorage:WaitForChild(“Viewmodel”)
local module = require(game.ReplicatedStorage.MainModule)

viewmodel.Parent = game.Workspace.Camera
module.weldgun(gunmodel)
module.equip(viewmodel, gunmodel)

game:GetService("RunService").RenderStepped:Connect(function(dt)
module.update(viewmodel, dt)
end)

module:
local module = {}

function module.update(viewmodel, dt)
	viewmodel.HumanoidRootPart.CFrame = game.Workspace.Camera.CFrame
end

function module.weldgun(gun)
	local main = gun.GunComponents.Handle
	
	for i,v in ipairs(gun:GetDescendants()) do
		if v:IsA("BasePart") and v ~= main then
			local motor = Instance.new("Motor6D")
			motor.Name = v.Name
			motor.Part0 = main
			motor.Part1 = v 
			motor.C0 = motor.Part0.CFrame:inverse() * motor.Part1.CFrame
			motor.Parent = main
		end
	end
end

function module.equip(viewmodel, gun)
	local handle = gun.GunComponents.Handle
	local hrp_motor = viewmodel:WaitForChild("HumanoidRootPart").Handle
	
	gun.Parent = viewmodel
	hrp_motor.Part1 = handle
end

return module

edit:
by making the animations it just ignored it nvm

2 Likes

Hey! In the future, if you’re experiencing this try anchoring and unanchoring the parts. Just putting this here for future users having the same problem.

2 Likes

So I tried the tutorial but the character still spawns when I run the code how can I fix this?

Can you elaborate more or send a video showing this, I don’t quite understand on what you’re trying to say.

Like when I hit play the camera has the arms attached to it but my regular character still loads in

Yeah it is supposed to load in, when you go first person your character would go invisible. I don’t really see what’s going on here or the problem?

Woops I didn’t set the camera to go to first person my bad

I had the same problem too, but it’s just a simple mistake, try anchoring 1 part from your gun, that helped me out, alot

2 Likes

Wait that does help? I thought it was from the custom character messing something up, I will try that!

EDIT: That fixed it! I will continue this tutorial, thank you so much!

2 Likes

i am kinda new to this stuff but i am confused on how to make motor6d?

You can just insert it by using the + icon.

https://gyazo.com/7d4495ac4490dc8c5cd04d3117ace86e

oh alright lemme see if motor6d is insertable or not

https://gyazo.com/e80a4b05a1336c133d7f8386281470d7?token=c649a2913324e49700bb14a1b46f2dbd

can’t insert it doesn’t show