Sitting down with flexiskirts [UPDATED]

This looks badEvery girl who tried a flexiskirt once (how can you resist not buying them…?) knows about the problem: they look fantastic when standing up, but completely nasty when sitting down.

The image here shows what happens. Flexiskirts, unlike mesh-based skirts (also known as ugly Linden skirts) simply don’t follow your avatar’s skeleton, but gravity. There is nothing you can do about it: the skirt will always be “inside” the chair where you sit on.

Or is there a solution?…

Linden Lab sometimes comes up with clever things. In fact, flexible prims (“flexies”) was one of the cleverest things ever done. We can’t live without them anymore, and “Linden skirts” are completely out of fashion these days, so what can we do about it?

Well, a little-known trick is that flexies are not only affected by gravity, avatar movement, and wind. Unlike Linden skirts (which are, of course, not scriptable…) they can also be affected by a mysterious “force” as well — one that you can define either on the prims itself or use scripting.

So here is the idea behind this concept: detect when the avatar is sitting down and apply a force to the flexiprims so that they point forward (in the XY plane where your avatar is sitting). That way, they won’t “go through the chair”! You can adjust this force to make it look more or less natural; the prims are still flexi, so they’ll still move around with wind (if the force is not too strong), and they’ll continue to be affected by gravity a tiny bit, so they’ll bend from the point of origin (usually your waist), ie. they won’t look like solid planks 🙂

A few extra tricks are needed. First, it’s a pain to use a script on each and every flexiprim on a skirt (you’re definitely going to miss a few). Thankfully, LL is listening to us, and they gave us a new LSL function: llSetLinkPrimitiveParams(). With that, you can change all prims on the same linkset with just one function call in a single script! It’s very, very useful.

Is that all? No! 🙂 Sadly, we need some math to figure out how to apply the force. You see, forces are vectors, and the first thing you need it to figure out which way your avatar is facing when sitting down, and make sure that you apply the force in the right direction! Since I’m not good at maths, I’m cheating a lot — the force in this case is just on the XY plane (so I ignore the Z bit) and that should be good enough for most cases. Feel free to add more complex math on the comments 😉

This particular script is not automated, ie. you need to touch your skirt to change it from a walking to a sitting position. But this can be automated! Since it requires a timer that checks if you’re sitting down or walking around, that creates a bit of lag, though, so I’ve avoided it.

Here goes the script:

// Gwyneth Llewelyn's Flexi Vector Changer,
//  ... or: how to get flexiskirts to work properly when sitting down!

// Works by touching and flipping through the two status: staning up/sitting down
//  To-do: interface with an AO so that it works automagically

list FlexiState;
integer isSit;

default
{
  state_entry()
  {
    // save current state
    FlexiState = llGetPrimitiveParams([PRIM_FLEXIBLE]);
  }

  changed(integer what)
  {
    // if someone is tweaking the flexi settings, you better reset!
    if (what & CHANGED_SHAPE)
      llResetScript();
  }

  touch_start(integer total_number)
  {
    if (llDetectedKey(0) == llGetOwner())
      if (!isSit)
      {
        isSit = TRUE;
        llOwnerSay("Skirt in sit mode");

        // ok, we know the rotation. Now we need to figure out the bloody angle in the XY plane!
        rotation avatarRotation = llGetRot();

        vector PointForward = <1.0, 0.0, 0.0>;      // get a unit vector!

        PointForward *= avatarRotation;  // do vector rotation
        PointForward.z = 0.0; // clean Z as well, you never know; now this vector should be on the XY plane

        // amplify magnitude!

        PointForward.x *= 10.0;
        PointForward.y *= 10.0;

        llSetLinkPrimitiveParams(LINK_SET, [PRIM_FLEXIBLE] + llListReplaceList(FlexiState, [PointForward], 6, 6));
      }
      else
      {
        isSit = FALSE;
        llOwnerSay("Skirt in walk mode");

        llSetLinkPrimitiveParams(LINK_SET, [PRIM_FLEXIBLE] + FlexiState);
      }
  }
}Code language: LSL (Linden Scripting Language) (lsl)

And the result does certainly look much nicer!
This looks much nicer
Now, how to use it. You need a modifiable skirt, and one that only has flexiprims — just drop the script inside it while you’re standing (it’s very important to do that when standing). A few designers, however, mix flexies and regular prims on the same skirt (and these days, modifiable objects are harder to get). Please note that if just a single prim is not a flexie, this script will not work. Trust me: I’ve broken a few skirts that way 😉

If you know of a skirt designer that just sells non-modifiable skirts, or ones that combine flexiprims with regular ones, well, give them a copy of the script and make sure they start using it on all their work 😉

[UPDATE] For some silly reason, a lot of skirt designers use an invisible ball on the centre of the skirt, which is allegedly there to “make adjustments easier”. Often this invisible ball is also the root prim (the one that shows yellow when right-clicking on the skirt on the ground and selecting Edit).

This is what you have to do to use this script on these types of skirts:

  1. Drop the skirt on the ground.
  2. Right-click and select Edit
  3. Check the box that says Edit linked parts
  4. Right-click now on the root prim (the one in yellow)
  5. If it’s a sphere, change it to a cube
  6. Now go to the Features tab and activate the Flexible settings on the checkbox
  7. For best results, the parameters should be exactly like the ones on the other skirt elements (I usually select one of them, take note of all the parameters on a piece of paper, select the root prim again, and copy them)
  8. Throw the script above inside the root prim
  9. Take the skirt back into inventory
  10. Now wear it!

Complex? A bit! So, make sure you have a copyable version of your favourite skirt, I broke quite a lot of them until I figured out all the steps… but it works nicely!