Jump to content

Rotate an attachment so it always stays upright?


FoxyByNature
 Share

You are about to reply to a thread that has been inactive for 1337 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Please point (ha!) me in the right direction with this...

I've been trying to add a script to an animated (flying) attachment I have, so that it always stays upright when I sit on a chair which causes my avatar's rotation to change (for instance lying down or inclined).

It's also important that the attachment remain facing the same way as my avatar is looking, in a horizontal plane I mean, at least mostly.

I've had partial success with the following code. I tried it by sitting on a cube and rotating it with the edit controls, while wearing the attachment. The attachment was continually adjusted to stay upright if I rotated the cube seat's x and y, but not z at the same time, or z alone but not x or y. If I tried rotating all together, the attachment just went to an odd angle. I'm guessing I need something like llRot2Up, but my brain started melting and my many experiments have failed. As has searching although surely I'm not the first to want to do this.

rotation avatar_rot;
vector avatar_vec;

default {
    state_entry() {
        llSetTimerEvent(0.5);
    }

    timer() {
        avatar_rot=llGetRot();
        avatar_vec=llRot2Euler(avatar_rot);
        llSetRot(llEuler2Rot(<avatar_vec.x,avatar_vec.y,0>));
    }
} 

The code goes in the attachment's root prim. I can usually script quite well, but rotations just hurt.

Edited by FoxyByNature
Link to comment
Share on other sites

Sorry, the bad news is you can't do what you want to do, at least not satisfactorily. 

The good news is it has nothing to do with quaternions. ;)

The reason it's not really possible is that scripts can't know the orientation of the animated avatar because animations are played on the viewer; the sim just has no idea what they look like, so if the animation turns the avatar or moves it into a seated position, there's no way for a script to know about that.

Now, there are some half measures that are sometimes taken that work some of the time. One is to ignore all the many errors that will be introduced by animations and only worry about the rotation and translation of the single point that represents the avatar. (That does involve quaternions -- and is mostly useless anyway.) Another is to take into account the rotations imposed by specific animations, individually, that the avatar is playing. (A variant is to assume that all sitting animations are identical, which is hopelessly wrong most of the time.)

Couple of other options: Instead of rotating an attachment, use an unattached object and move it around with the avatar. This will probably look ridiculous if it's supposed to appear attached to some part of an animated avatar, but you mention the attachment is "(flying)" and... I dunno, maybe. The other possibility that comes to mind is to hide the attachment's surface altogether and replace it with a particle (or maybe several ribbon particles?) that maintains orientation but moves with the emitting object. I'm guessing that won't be very appealing either.

  • Thanks 1
Link to comment
Share on other sites

D'oh! Yes, I sort of did know that, but it seemed to be almost working so it didn't really make it into my brain.

Thank you Qie, at least I know now even if I don't like it. No wonder hours of searching didn't turn up a solution.

No, those workarounds won't really work here but thanks anyway. I've used particles like that before though. Guess I'll just have to put up with things as they are.

I'll go back to playing with BOM. I love that! So many tattoos... such little time; now I can wear them all at once again! (and look an unholy mess 🤣 )

  • Like 1
Link to comment
Share on other sites

as a starting point,  when attached to skull (or any other head attachment, like eye) then the attachment will kinda 'look" at where the avatar is looking. Our floating/flying movement can then be applied, moving our object relative to the direction in which it is 'looking'

as Qie mentions, and you realise, this doesn't solve every issue tho. Like when the orientation of a playing animation is unknown. Is just a starting point

Link to comment
Share on other sites

9 hours ago, Ivanova Shostakovich said:

   The world-relative rotation of an object attached to Avatar Center does not change with avatar animations and movement.

Now that you mention it, this could be useful in this case. It's not going to correct for animation-imposed rotation of the visible avatar (so the attachment can't reliably "remain facing the same way as my avatar is looking") but I guess it would "always stay upright" and so overall it's probably the closest to a viable workaround.

 

Link to comment
Share on other sites

That does indeed do the trick well enough. I can live with it not facing forward when I'm not stood up and there's only a short 'start-up' sequence where the avatar might not be where expected due to its animation moving it away from centre. Not a problem - I'll get rid of that bit of the fairy's animation.

My fairy is now attached to avatar centre and no longer takes a nose dive if I sit down. Thank you all for the help.

Edited by FoxyByNature
  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1337 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...