Okay so I checked the position of the barrel and the whole model and somehow it’s super far away. But, it shows on my screen as being right in front of me. I’m not sure what causes this.
Okay I figured it out. I guess I am dumb because I spent at least an hour trying to solve this. But, the problem was the viewmodel wasn’t anchored.
EDIT: Animations don’t work when anchored. So I guess I still need help.
EDIT EDIT: Turns out you can solve this issue by making only the humanoid root part anchored.
Maybe this can be a mistake with the welding? I’ve had this issue before but unfortunately I couldn’t remember what I did to fix it.
Edit: I didn’t see the edit you made, already wrote the post 30 minutes ago forgot to send lol
A Bit of topic but what colors do you use for your studio scripts?
This is terrific, I love this work, keep up the good work
I’m actually using vscode, but the theme is Palenight.
If you’re talking about roblox studio theme here:
Ok so I tried setting the Part0
to the humanoid root part and Part1
to the left arm, but whenever I do that it just sets the humanoid root part position to the left arm. Which completely screws up the look of the view model.
I don’t know if this is supposed to happen but it’s really irritating me.
This is a common thing. To not mess up you either have to use the command bar and inverse the CFrame or just use a plugin. I use this plugin to rig models. RigEdit Lite - Roblox
Plugin really helped, thank you.
Mine as well, but i fixed it by anchoring humanoidrootpart and all of it was working fime
I am having an issue where the gun is not in front of my face. It in fact on the far left of the viewmodel, and it also is off the screen. However, it still moves with it, which makes me think that for some reason there is a huge offset with the viewmodel and the gun’s handle. I don’t know why this is happening.
Local handler script
local gunModel = game.ReplicatedStorage:WaitForChild("A-47"):Clone()
local viewModel = game.ReplicatedStorage:WaitForChild("Viewmodel"):Clone()
local mainModule = require(game.ReplicatedStorage.MainModule)
viewModel.Parent = game.Workspace.Camera
mainModule.weldgun(gunModel)
mainModule.equip(viewModel, gunModel)
game:GetService("RunService").RenderStepped:Connect(function(dt)
mainModule.update(viewModel, dt)
end)
Main Module script
local module = {}
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 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
function module.equip(viewmodel, gun)
local gunHandle = gun.GunComponents.Handle
local HRP_Motor6D = viewmodel:WaitForChild("HumanoidRootPart").Handle
gun.Parent = viewmodel
HRP_Motor6D.Part1 = gunHandle
end
function module.update(viewmodel, dt)
viewmodel.HumanoidRootPart.CFrame = game.Workspace.Camera.CFrame
end
return module
The Motor6Ds all seem to be connected properly.
Make sure the HumanoidRootPart is anchored.
Thanks! Also, for people reading this, if you cannot see your gun even after you have applied any fixes make sure it is actually pointing forwards, as it can be facing the side and thus it appears that it is not attached to your humanoid root part correctly.
I don’t understand this line of code:
luaNewMotor.C0 = NewMotor.Part0.CFrame:inverse() * NewMotor.Part1.CFrame
After some googling I still do not properly understand what the C0 property of a motor6D is, and why was the inverse function used in this case?
I’m new to motor6D lol
C0 means the Part0’s offset. We need to inverse the CFrame fix the position of the part’s CFrame.
I still dont understand how the inverse function is used to ‘fix’ the position of the part’s (what is ‘part’s’? Is it C0 or C1) CFrame, and why do you multiply it by Part1.CFrame
I looked at this post: What is ```CFrame:Inverse()```?
Are you basically subtracting one CFrame from another? What is the purpose of this?
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.
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.