How to Weld a Mesh To Another Animated Mesh

How do I weld a mesh to an animated mesh? Say you are making an FPS game with custom animated mesh for the player’s hands. In my game I have custom animated mesh for my player’s arms. Each weapon within the game have a set of animations baked with the specific to the weapon’s bones. Im at the point where Id like to place weapon attachments onto the weapon- more specifically attaching various scopes onto a gun.

Some things I’ve tried:

  • parenting the scope mesh to the animated arms mesh (which also has the weapon). This results in the scope staying in place due to no prior animation bone data for the scope.
  • Weld constraint. Can only be used on parts. Neither my weapon or arms mesh consist of parts.

Does anyone have any suggestions? One last thing I have in mind are using IK (which i prefer to avoid for the FPS animations as they tend to be buggy) or using renderedstep and render the position of the attachments each frame up at a higher priority than the camera’s first draw call. This might work but adds more pain of tracking the weapon mesh in 3d space

5 Likes

Have you tried welding the attachment to the gun model itself

This didnt work. While the animated skinned mesh (a single model with arms and gun) shows a reload animation properly the welded attachment (in this case an iron sight depicted as the floating rectangle) remains at the welded location. Welded Constraint is fine for unanimated meshes but since mine is animated it should update each frame but doesnt.

I did approx. 30 seconds of googling and found this post, does this work?

Also, in the future I suggest using “Help and Feedback Building Support” instead of development discussion for these types of posts! :slight_smile:

I quickly looked at this and it doesnt help as I am already doing something similar. The animation was made Blender using separate meshes. I export in a similar way so that in game they are actually multipart meshes using one animation :

image

The problem here is that the animation and its bones are baked. So if I used the same approach with baking the animation Id then be stuck creating baked animations for a reload, shoot, idle, walk, run animation for each weapon with each attachment. So this isnt do-able.

I was hoping to attach the weapon attachments using built-in roblox components like Weld Constraint or Motor6D components… but I dont think they update with the weapon’s bone. Im beginning to believe I’d have to do a hacky frame by frame update. :\ which isnt too bad but sucks since id also compute the offsets per frame in each animation.

Also. I updated the topic to “Help and Feedback Building Support”. But I believe this may become more of a code related topic if none of the built-in constraints work.

Can you show me what you’re doing exactly? Please dropdown the children of these objects that you’re posting about.

Another possible solution while I’m at it:

When I was struggling with similar problem, RigidConstraint helped me.

1 Like

That didnt work. Also I made replies to that post a while back.

Try RigidConstraints and then come back and tell us if it worked.

I can search for more solutions later as I’m finishing up a major update to a system of mine.

Thank you this worked!

But I had to do the following:

  1. modify existing rig to add a new bone called rear-sight-mount (used as reference for where the model will attach to)
  2. create a new separate 3d model of the attachment including a bone called sight-mount (again used as reference on the red dot sight)

I was then able to export a new animation which includes the new right in step 1. I then created a rigidconstraint and set the model in step1 as attachment0 and set the attachment model from step2 as attachment1.

1 Like

Update: Rigid Constraint works.

But for some reason even though the bones line up in Blender, when using RigidConstraint it applies a strange offset (rather than center the origin is offcentered?)

Blender how it should look like:

Roblox (rigid constraint uses origin as the left most position?)

Rigid constraint will snap both attachments to the same CFrame.

Well, I understand they share the same CFrame. I intentionally positioned them in Blender such that they are aligned correctly. Why is there an offset in the roblox engine when using rigidconstraint?

Update: Nevermind the offset was due to improperly setting the bone in Blender.

Rigid constraint works perfectly fine given the following quirks it has in my findings below:

  • attaches only to bones
  • attachment models must have their own armatures exported with bones reference where to mount
  • no way provide an offset (useful to defined different offsets for varying guns. for example a red dot sight is positioned at different locations across various guns)
1 Like

Can’t you move the attachment?

No. The mesh uses the armature’s bones for the CFrame position. When you try to move it will snap back into its original place. Its ridiculous.

I mean you could just move the mesh with the other mesh

Well yes but that will only work for one gun. If I attach it to my other 20 guns then we arrive at the same problem where some guns will have the sight attached at an incorrect location on the barrel…

Pistols vary in length shape and size. Rifles vary even more.

Could you just have a different animation for each gun?