On the line…

Last week I got a bit distracted trying to make an interactive washing line in Unity and Playmaker. As usual, I though I’d share what I came up with; a combination of rigid-bodies, skinned meshes and line-renderers…

It’s a solution very similar to how I set up my adjustable power-lines a while back; control points of a line-render parented to relevant geometry. I wanted my clothes-line to be inteactive though, so the next step was introducing a couple of rigid-body hinges…

 

 

The sphere in the middle at the top is a kinemetic rigid-body, the sphere directly below that is another rigid-body connected with a hinge. The top curve is drawn between the two spheres either side and this hinged sphere, using the Draw Curve Playmaker action I made a while back. I’ve added another hinged point to the bottom to simulate an item of clothing hanging from the line.

This works well enough for the rope itself and for a single thin/small item attached to the middle, but you’ll run into some issues with larger items or items placed anywhere else along the curve…

 

 

The t-shirt above is too wide to be deformed by just one point so the sleeves float outside the curve, the further you move from the middle the worse this will become. What we need is to be able to pin objects to points along the curve itself as it updates.

 

 

The LineRenderer component in Unity has a GetPosition method which returns a Vector3 from the point along the line at a specified index. I created a new Playmaker action, adapted from an already existing Arraymaker action for getting Mesh points, that cycles through each point and stores its position in an array. It’s then just a matter of picking the points you want and matching your objects position to this every frame, in this case the yellow spheres.

There is another LineRenderer method that gets all the positions at once which is probably going to be more efficient, but I couldn’t get it to work with Playmaker’s native array system, that might be a better option if you doing this setup via script.  

 

 

These are two Skinned Mesh Renderers, with their respective bones connected to the curve via hinges in exactly the same way as before. I’ve added a constant forces to some of the hinges in an attempt to simulate some wind, at some point I’ll also try impulse forces based on mouse input like I did for the smashing pots.

You can find links to all the Playmaker actions via the forum here: http://hutonggames.com/playmakerforum/index.php?topic=16079

 

As ever, if you have any questions, crits or corrections, leave them in the comments below.

You can also follow along on Twitter for more regular updates.