Weldconstraint stops working when Part1 is unanchored?

This is a continuation of my previous post,

My weld constraints just stop working whenever the sleeves are unanchored, the sleeves have to be anchored in order for the weld constraint to work, but that stops any sort of viewmodel animating, which is really bad!

for a better explanation, see one of my replies on this post

local function ClothesToViewmodel(viewmodel: Model)
	local activeShirt = char:FindFirstChildOfClass("Shirt")
	
	if not activeShirt then return end
	
	-- we're cloning the sleeves right here, duh!
	local sleeves = viewmodelSleevesFolder.BaseShirt:Clone()
	
	sleeves.Parent = viewmodel
	
	-- creating these variables because idk i find it
	-- a lot more organized
	local leftSleeve = sleeves.Left
	local rightSleeve = sleeves.Right
	
	-- the viewmodel arms
	local leftArm = viewmodel:FindFirstChild("Left Arm")
	local rightArm = viewmodel:FindFirstChild("Right Arm")
	
	-- we create the weld constraints :^)
	-- why via a function?
	-- that's a really good question! i don't know!
	local leftWeld: WeldConstraint = CreateWeldConstraint()
	local rightWeld: WeldConstraint = CreateWeldConstraint()
	
	-- parent the welds!
	leftWeld.Parent = leftArm
	rightWeld.Parent = rightArm
	
	-- oh yeah and also parent the sleeves
	sleeves.Parent = viewmodel
	
	-- we set the welds to the left first
	leftWeld.Part0 = leftArm
	leftWeld.Part1 = leftSleeve
	
	-- then we do so for the right!
	rightWeld.Part0 = rightArm
	rightWeld.Part1 = rightSleeve
	
	-- oh yeah we also make the sleeves non collideable
	leftSleeve.CanCollide = false
	rightSleeve.CanCollide = false
	
	-- make the sleeves unanchored so the viewmodel can animate (this doesn't work bruh?)
	leftSleeve.Anchored = false
	rightSleeve.Anchored = false
end

i’ve decided to go with making models for the player character and the viewmodel

now, for the player character, aligning the position is quite simple, just pivot the clothing to the torso/rootpart

but for the viewmodel, i’m not exactly sure how to do that,
i am using the viewmodels you can find anywhere in the toolbox, they have a fake camera part blah blah blah

now the thing is, if i try to pivot the sleeves to the viewmodel’s primary part, it uhm, it doesn’t really work

this is the only thing i’ve tried so far,
does anyone know how i could get the positions down perfectly?

as far as i know, pivoting the sleeves to the left and right arm respectively would result in the sleeves being on the “forearms”, if that makes sense

open to suggestions

2 Likes

if the sleeves are meshes - add a weldconstraint.

Example
Right Sleeve [Mesh] = Part0
Right Arm [BasePart] = Part1

basically applies the weld at each centre point for each part.

hmmm

i really like your idea,
but i don’t think it quite works

or maybe i just did something incorrectly?

local function ClothesToViewmodel(viewmodel: Model)
	local activeShirt = char:FindFirstChildOfClass("Shirt")
	
	if not activeShirt then return end
	
	-- we're cloning the sleeves right here, duh!
	local sleeves = viewmodelSleevesFolder.BaseShirt:Clone()
	
	-- creating these variables because idk i find it
	-- a lot more organized
	local leftSleeve = sleeves.Left
	local rightSleeve = sleeves.Right
	
	-- we create the weld constraints :^)
	-- why via a function?
	-- that's a really good question! i don't know!
	local leftWeld: WeldConstraint = CreateWeldConstraint()
	local rightWeld: WeldConstraint = CreateWeldConstraint()
	
	-- we set the welds to the left first
	leftWeld.Part0 = viewmodel:FindFirstChild("Left Arm")
	leftWeld.Part1 = leftSleeve
	
	-- then we do so for the right!
	rightWeld.Part0 = viewmodel:FindFirstChild("Right Arm")
	rightWeld.Part1 = rightSleeve
	
	-- and after all of that, we parent the sleeves to the viewmodel
	sleeves.Parent = viewmodel
end

the result is the same btw

could u show what it looks like when playing with it welded, as well as - if you are making it a mesh make sure u make it CanCollide = false

sorry i fell asleep

uh, i also made sure to parent the welds to the arms;

the result is this, even with weldconstraints;

this is definitely the correct way to do this, it’s just something is not working

okay, the problem exists in the Anchored property,

just for the sake of it, i decided to anchor the sleeves
when the sleeves are anchored, they do get welded, but restrict any sort of viewmodel animations (which is bad!)

so i figured i’d just unanchor them via code, but that just puts us back at square one
interesting…

going to edit the title so the post is more appealing :grin:

Is everything made at runtime? Arms, Weapons, etc? Or is there a predefined pair of arms with a weapon for each set of arms?

You stated that you’re using a random viewmodel from the toolbox, which could be setup in a number of ways.

Personally I keep my viewmodels in a seperate folder, generally as team viewmodels so maybe a pair of arms with long camo sleeves, and maybe a pair of arms with short sleeves and gloves.

I then Instantiate Motor6D’s to connect weapons to the arms and allow for animations I premade to play correctly.

If you’re not sure how the viewmodel is setup and you want to attach the clothing to the arms at runtime your best bet is to weld the clothing to each individual arm and adjust the C0 property to align the clothing with the arms. You could avoid this step if you made the clothing and the arms in 3d software and have the origin set to the same position and rotation.

And as a tip generally you want everything except the cameraPart in viewmodels to be un-anchored or you get some weird activity, the camerapart should always be anchored!

i’m not sure if this was the best way to do this, but according to all the tutorials i saw on youtube, i just went with this method:

image

each model seen in this folder is an individual pair of arms, camera, weapon, etc.

the sleeves are stored in a seperate folder and copied when they need to be, thus they are applied on the arms everytime,

the reason why i’m not just storing arms with pre-set clothing, is because the game will eventually have some sort of customization system

…yeah i’m not doing this as of right now, sorry


i am pretty sure that the majority of the viewmodels i saw were setup in the same way

but yeah, the sleeve meshes are modeled in blender on the viewmodel, then they are rendered without the viewmodel, so the position should always be perfect, it should just be welded and that’s it

and it seems i was right about this, as the image i’ve sent a small bit above (where the sleeves are anchored), shows that the sleeves have correct positions, they just don’t wanna stay welded when anchored

this is very confusing now

Not a bad method, especially if you want to avoid messing with Instantiating Motor6D’s and whatnot.

Since you’re going to want clothing customization welding is definitely your best option.

I went ahead and setup clothing instantiation for a viewmodel.

Here’s my result:

I made a clothing folder and put meshpart that was modeled on the arms being used inside:

image

My code for applying the clothing was very basic, this function is called from the module script that sets up the rest of the viewmodel:

local function fetchClothes(VM)
	local sleeveL = game.ReplicatedStorage.Clothing.Sleeve:Clone()
	local sleeveR = game.ReplicatedStorage.Clothing.Sleeve:Clone()
	
	local armL = VM.ArmL
	local armR = VM.ArmR
	
	sleeveL.Parent = armL
	sleeveR.Parent = armR
	
	local w1 = Instance.new("Weld")
	w1.Parent = armL
	w1.Part0 = armL
	w1.Part1 = sleeveL
	
	local w2 = Instance.new("Weld")
	w2.Parent = armR
	w2.Part0 = armR
	w2.Part1 = sleeveR
end

The viewmodel being used is set up as follows:

image

With only the “CameraPart” being anchored

And finally the properties of the clothing is as follows:

image

Hopefully this is enough information to help get your setup working, if not I’m happy to further help!

just before i attempt this

what exactly is the difference between Welds and WeldConstraints?

I’m actually not sure about that one, I just always use normal welds. :man_shrugging:

okay uh

it semi-works?

for whatever reason, the welds just weld the sleeves to the center of the arms, which is bad!

this gives me a horrible, but i think a working idea

  1. anchor the sleeves
  2. move the sleeves to the appropriate positions using WeldConstraints
  3. use Welds to actually weld the sleeves
  4. remove any WeldConstraints and unanchor the sleeves

That could work, a little hacky but not the end of the world.

I’ve done a little extra research on WeldConstraints because of your question and it seems that WeldConstraints automatically fill in some extra information and are newer.

If you ever want to move away from the hacky solution you can change the C0 property of welds to align the clothes with the arms.

how exactly can i tamper with C0 (and C1?)

i have never really worked with welds and this is kinda confusing

i’ll try my hacky fix since i don’t have much else to do while waiting for a reply

The C0 property is simply a CFrame offset, applied to the welded part.

Here’s an example where I adjust the C0 to position the gun on the viewmodel I showed. I will note that I’m adjusting the C0 on a motor6D here but it should be the exact same on a weld.

RealConnect.C0 = VM.ArmR.gunPos.CFrame * CFrame.Angles(gun:GetAttribute("Rotation").x,math.rad(gun:GetAttribute("Rotation").y),gun:GetAttribute("Rotation").z) + Vector3.new(0,-0.03,0)

Edit:

Here’s a breakdown:

The “gunPos” is an attachment inside the armR positioned about where I want the gun to go, I then apply a CFrame rotation to rotate the gun to face the correct direction, and apply a Vector3 offset to lower the gun in the arm slightly.

cframe math :slightly_frowning_face:

so uhhh, how would i rotate the sleeves and put them on the shoulders?
i’m not really good at this, especially when i don’t have an attribute called rotation :sob:

Step 1. You’re going to be finding out which direction you’ll want to rotate the sleeves, I had a problem a while back where I had to find out the correct rotations for a lot of weapons which were modeled in different software so their origins were all wonky.

The fastest way I found to get the correct rotations is to utilize the console, you should be able to take your code and input it into the console with a few changes like making the viewmodel appear at a known location and adjust the rotation value until you figure out the correct rotation from your picture it seems only one value will need rotated either 90 degrees or -90 degrees to line up the sleeves.

Step 2. Once you’ve found out the correct rotations you should probably store them somewhere easy to access, I used an attribute for the gun as it’s quick and clean.

Step 3. Apply the rotation, the math should just be something like `weld.C0 = sleeves.Left.CFrame * CFrame.Angles(the rotation you found)

Step 1 is the hardest part, only because it’s tedious. If you want to constantly restart your game you can edit your code to apply different rotations.

Edit:

For step 1. You could even just pull out one of the viewmodels and use just the code for instantiating the clothing and just apply it to the viewmodel you have in workspace to find the correct rotation rather than copying all of your code.

i don’t think step 1 is happening

rotating the sleeve by like -90 on the x axis results in this:

i think the reason this happens is because it’s a modeling issue, but i really cannot be bothered

i don’t think welds is the way to go now :pensive:
gonna try tampering with constraints again

Yeah, seeming like a modelling issue to me too.

Only other thing I can think of is getting a copy of your viewmodel setup, and messing with it myself.

Anyways I’ll be around for a little while longer if you need more help. Just let me know and Good Luck!

welds allow u to move the cframe for each part. WeldConstraint doesn’t. Don’t Anchor the sleeves. Also see if you can use bodyposition then position each sleeve pos to each arm position. then the bodyposition instances will handle the physics.

local BodyPosition = Instance.new("BodyPosition")

BodyPosition.Parent = -- //Sleeve

Sleeve.Position = Arm.Position

BodyPosition.Position = Sleeve.Position


--// handle the rotation of the sleeve
Sleeve.CFrame = Arm.CFrame