a tale of Wyverns, Dragons and Ponies

The Hedgehog Wheel

February 22nd, 2008 Posted in Isle of Wyrms

The task, make a Hamster Wheel for Hedgehog avatars for the upcoming Isle of Wyrms Hedgehog Spring Festival.

The requirements, an avatar can sit on the wheel and when they do so, they would start rolling and so would the wheel. Since the Hedgehog avatar made by Daryth Kennedy comes with a rolling animation (which was copy perms) and in theory it was only a case of bolting the wheel animation onto a standard pose ball script, it didn’t sound all that complicated…

Making the Wheel

The first step was to make the wheel that the hedgehog would roll inside and the scripts to provide the “rotating” effect. The wheel was a simple hollowed cylinder, with a second thin cylinder to provide the hub and spokes.

There were two techniques that I could use; animate the texture of the wheel using llSetTextureAnim or to rotate the whole prim using llTargetOmega.

Initially I choose to use llSetTextureAnim as this is the more conventional approach. This function offers both rotate, scale and frame by frame animation modes. To control the “rotation” animation for the test wheel I used a simple two state approach with the on_touch event being used to switch between “On” and “Off” states.

For the prim that contained the wheel hub and spokes, this worked very well and smoothly rotated the inner texture around the pivot point. The only issue was that two separate commands had to be used to rotate the front and back of the prim - this would mean in lag the textures would probably not be synched.

However, for the “roll” surface this worked less well. The issue with the llSetTextureAnim function is that it sets the texture to 1:1 scaling during animation irrespective of the actual texture scale setting applied to the prim. To achieve the desired effect I had applied 6x horizontal scaling and the animation function was setting this back to 1x - Ugh! One workaround would be to change the texture to incorporate the 6x horizontal scaling, but in order to maintain a sensible resolution the texture would become large (1568 x 256 in this case) and thus add to lag.

llTargetOmega

So, the alternative is to use the llTargetOmega fuction. This rotates the prim the script is contained in (unless that prim is the root-prim where it will rotate the whole object). Since the object I was making was non-physical, this processing would be done in the client and thus very low lag.

However, my “Off” state did not work correctly! The prim refused to stop turning. A quick search found that there was a bug in the function that llTargetOmega doesn’t update unless the object is interacted with by an AV! It wasn’t possible to stop the object turning using the script.

My workaround? Well since the spin rate is a float value, I set it to something very small, I used 0.0001 in this case. Since a value of 1 is a rotation of 1 radian per second, a value of 0.0001 is one rotation every 62,831 seconds or ~17 hours. Being a 32-bit float I could go smaller, but this was adequate to ensure movement was not instantly apparent!

Pose Ball

The next task is to make the “pose-ball” that would trigger the animation and send the commands to the wheel. I used a standard pose-ball script and added Daryth’s Hedgehog Roll animation. To make the pose-ball work with the wheel, I just linked it to the wheel (making the pose-ball the root prim) using llMessageLinked to communicate with the wheel in the show() and hide() methods. After replacing the on_touch events with link_message events, the wheel was good to go, so did it work?

Animation Override

Well yes and no. The wheel would have worked, but tiny avatars such as the hedgehog incorporate an animation-override - this is to keep the avatar looking correct regardless of what the avatar is currently doing, walking, running, swimming, etc. The default animations are meant for human avatars and are not for specialised avatars where the human frame has often been contorted.

Fortunately the script library also contained a handy AO Overriding Pose Ball Script! This relies on the fact that when the avatar sits on the object, the animation override will stop the default sit and then set its sit animation. To get the correct rolling animation, this script stops the default sit, the ao sit and then sets the desired pose. This relies on the fact most animation override devices do not periodically reset the pose.

To finish off I added a particle smoke effect for while the wheel was rolling.  So we now have a working Hedgehog Wheel - Weeee!

You must be logged in to post a comment.