Posted by: hmmopensim | June 27, 2009

Sitting Right With Sitballs

In case you missed Jenniver’s comment to the last post, adding sitballs to chairs and benches is another way to get people sitting correctly.  This is done by adding a script, with a single line of code which calls the llSitTarget() function.  This function takes two arguments, the first being a vector offsetting the avatar from the center of the sitball, and the second being a rotation type which rotates the avatar properly.

The displacement can be a bit tricky, and the Second Life LSL Wiki says that it is not exactly the same for male and female avatars.  The best way to set it seems to be to start the vector at <0.0,0.0,0.0> then adjust it and see where the avatar is sitting with respect to the bench.  It turns out that the adjustment is not quite what you would think.

The rotation type is a four element object called a quaternion, and setting it directly is rather complicated.  LSL has a conversion function which simplifies that.  That function is llEuler2Rot().  This function takes a vector which represents rotation about the x, y, and z coordinate axes of the sitball, with the angles expressed in radians.  Alt-printscrn won’t show these axes when you have the sitball in editing, so I’ll just tell you that in the images below, x is pointing out from the bench in the direction you expect the avatar to face when sitting, y is pointing to the avatar’s left, and z is pointing up.

SitBall1

Here is Ingemar trying to sit on the new pew I built for the chapel.  The inset is the sitball’s script, showing no displacement and no rotation. C’mon, Ingemar, a Lutheran Gottesdienst isn’t supposed to be that uncomfortable.  The first thing we need is a rotation about the y axis.  That axis is horizontal, and the positive direction points to Ingemar’s left.  The Right Hand Rule applies, which means that a rotation of -90 degrees, or pi/2 radians, is called for.

SitBall2

Now, that is an improvement, but next we have to get Ingemar up off the floor.  A displacement is called for, and you would think that this is a displacement in the z direction, since that is supposed to be up.  Actually, it’s not.  Take a look at the next picture, and look where the displacement actually is.

SitBall3

Look at the vector in the first argument of llSitTarget().  Notice that it is in the x component, not the z component.  And, it is -0.8, not +0.8.  Still, it gets Ingemar elevated properly.

The final step will be to move the sitball back a little so Ingemar can lean back against the back of the pew.  I’ll just do that by repositioning the sitball.

SitBall4

There we have it.  Ingemar is sitting right, although I hope he is not too uncomfortable sitting with that ball up his rear!  There is room for another avatar on the pew, and I’ll just copy the sitball to the other side of the pew, then link everything together.  The final step will be to copy enough pews to fill the chapel.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.