SakeTami
minionsart
minionsart

patreon


Setting up Interactive Chains using Joints

Hi all!

Here's a quick setup guide for a chain you can use in gameplay, next post is about shaders again don't worry :V.

After showing off the chains in Astro Kat on stream I got a lot of requests for the setup, so here it is:

Chain Link Mesh

I've attached the one I used, it's super simple though so you can make your own however you want. Just make sure that the pivot is near the edge like in the picture above.

Setting up the links

I'm using my Toon Metal shader from a while ago here

Drop in your chain link, this will be the attached point. Add a Rigidbody and set it to IsKinematic (No Gravity).

Duplicate the chain, and set it as a child of the first.

Offset the child so it's in the right place for a link, for mine I had to set the Rotation.z to 90 and the Position.z to -0.2, but it depends on the orientation of your model.

Set the Child Rigidbody to Use Gravity and not IsKinematic.

Adding Joints

Add in a Configurable Joint to the child link, add set the parent as the connected body.

Aaand it's gone

If we hit play now, the link will fall through. so we need to change a lot of settings

First set the X - Y - Z motions to "Locked". Now it won't fall down anymore.

Now it needs collision, add a Box Collider to both the child and parent, don't make them too big. And turn on Enable Collision on the child joint

That's looking much better

Auto Connecting Joints Script

We can auto connect joints to a parent using this line in Awake:

Here's a link to the script: Pastebin 

Add this script to the child link, then copy it a few times, with every new copy being a child of the last. To however long you want the chain to be. Add the same offset you've set earlier.

Almost there, but the movement needs to be a lot more limited.

Add some Drag to the chain Rigidbodies (depending on how heavy/big you want them to be, I did 0.1)

Limit the Angular X - Y  Motion, Lock Angular Z Motion on all child links apart from the first child

Much better!

Adding a grab point

However, it really does not like being moved, looks like someone hit Sonic

The flip-out is because we are moving a child link, for a handle we need an attached joint that is outside of the group.

I'm adding a new mesh for gameplay readability, but you can use another link.

The handles' joint should be linked to the last Rigidbody in the chain. So make sure this one doesn't have the auto connect joint script!

Lastly set this handle to IsKinematic and not to UseGravity

The handle is done, but there is still some weirdness in the chains.

Select all child links and change the following parts:

Basically Limits and Dampers

Don't really have an explanation for these numbers, just a lot of tweaking in Astro Kat to get a good result

If you're still getting weird jittering, make the colliders of the chain smaller, they don't need to be big, it's just there so it won't fall through the floor.


Limiting Chain Movement

The final thing for gameplay integration is to limit how far we can pull the handle.

I set this up using ClampMagnitude

Get the distance from the first chainlink to the handle.

Then clamp this distance

Link to script: Pastebin 

The handle cannot go beyond the yellow sphere.

Limiting Player Movement

 For player clamping just do the same thing as the chain handle while grabbing, but you might want to turn off the collider on the handle when you use your grab command.

I've written a super simple version of gameplay interaction here.

Extended ChainHandle script: Pastebin 

Super simple movement script : Pastebin 

And thats the setup I'm using in Astro Kat ! Have fun

Setting up Interactive Chains using Joints

More Creators