Jump to content

Is this possible to do with a Sit script? (use current avatar position and rotation on sit)


Gawain Galtier
 Share

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

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

Recommended Posts

Is this possible to do with a Sit script? I'm trying to mainly sit on an object, but instead of sitting, i need to have the avatar do the following:

1. not change it's global position or rotation - llSitTarget needs to take the avatar's current position and rotation, and use those vectors / so to not alter the avatar's pos or rot. But it effectivly locks the avatar in his/her pos and rot.

 

2. while sitting, the avatar still needs to perform AO functions of crouch and stand / similar to his/her handheld device that is using related crouch and stand functions (animation, rezzing, hud chats, etc.)

 

Functional Example: i rezz my vehicle, and i sit on it, then i switch to a cleaning mode, where my avatar is standing and wiping on the outside of the vehicle, or kneeling and wiping (can be applied to mechanic roleplay etc.)

I basically need the avatar to sit on the object (so a region timer does not send the item back yet) but I need to roleplay things outside it.

Thanks for any valuable info!

Link to comment
Share on other sites

I haven't tried this solution, but it sounds plausible:

1. Avatar gets close enough to trigger a collision event that initiates a fairly rapid llSensorRepeat .

2. Repeating sensor keeps track of the avatar's current position and rotation until...

3. Avatar clicks to sit.  Use the most recent position and rotation to calculate the avatar's last LOCAL  coordinates relative to the root of your object. Kill the repeating sensor.

4. Use Strife's UpdateSitTarget routine to move the seated avatar to the calculated local position.  Use SLPPF to set the avatar's rotation equal to her pre-sitting rotation.

UpdateSitTarget does not actually change the sit target. The sit target stays wherever you defined it with llSitTarget. The routine moves the seated avatar to a new spot that you identify  -- that is, the position where the avatar was before sitting.

It's a little cumbersome, but worth a try.

  • Like 1
Link to comment
Share on other sites

Kind of. It's certainly possible to move the seated avatar all around the object on which they're sitting, and to do that movement dependent on which animation is playing (really, that's the basis of furniture engines like nPose), and to move them in response to controls (that, for example, is how I script seating "adjustment", in preference to X/Y/Z position and rotation dialogs), and that may be what you really need, but...

I don't think you can easily use the avatar's pos & rot from before they're seated unless the script collected it before they sat on a sitTarget (edit: as Rolig suggests, above). In my experience, that information is already lost once CHANGED_LINK occurs -- but only when the object has a sitTarget. Otherwise, if the avatar manages to sit on an object without a sit target, it seems to have its prior pos & rot for a brief instant after CHANGED_LINK, so you can kinda guess which part of the room they were standing before they sat. I've used that to put them in the animated "sitting position" nearest where they were standing, for example. So you might possibly be able to use that, if your object is easy to sit on without a sitTarget.

  • Like 1
Link to comment
Share on other sites

I don't think it truly deserves a commission.  Here's a bare bones script that does what I was describing:

UpdateSitTarget(vector pos, rotation rot){//Using this while the object is moving may give unpredictable results.    llSitTarget(pos, rot);//Set the sit target    key user = llAvatarOnSitTarget();    if(user)//true if there is a user seated on the sittarget, if so update their position    {        vector size = llGetAgentSize(user);        if(size)//This tests to make sure the user really exists.        {            //We need to make the position and rotation local to the current prim            rotation localrot = ZERO_ROTATION;            vector localpos = ZERO_VECTOR;            if(llGetLinkNumber() > 1)//only need the local rot if it's not the root.            {                localrot = llGetLocalRot();                localpos = llGetLocalPos();            }            integer linkNum = llGetNumberOfPrims();            do			{                if(user == llGetLinkKey( linkNum ))//just checking to make sure the index is valid.                {                    //<0.008906, -0.049831, 0.088967> are the coefficients for a parabolic curve that best fits real avatars. It is not a perfect fit.                    float fAdjust = ((((0.008906 * size.z) + -0.049831) * size.z) + 0.088967) * size.z;                    llSetLinkPrimitiveParamsFast(linkNum,                        [PRIM_POS_LOCAL, (pos + <0.0, 0.0, 0.4> - (llRot2Up(rot) * fAdjust)) * localrot + localpos,                         PRIM_ROT_LOCAL, rot * localrot]);                    jump end;//cheaper but a tad slower then return                }            }while( --linkNum );        }        else        {//It is rare that the sit target will bork but it does happen, this can help to fix it.            llUnSit(user);        }    }    @end;} //Written by Strife Onizuka, size adjustment and improvements provided by Talarus Luankey gAv;vector gPos;rotation gRot;integer gSitting;default{	state_entry()	{		llSitTarget(<0.0,0.0,0.1>,ZERO_ROTATION);	}		collision_start(integer num)	{		if (!gSitting)		{			gAv = llDetectedKey(0);			if (llGetLinkName(llDetectedLinkNumber(0)) == "Tripwire")			{				llSensorRepeat("",gAv,AGENT,10.0,PI,0.1);			}		}	}	sensor(integer num)	{		gPos = llDetectedPos(0);		gRot = llDetectedRot(0);	}	changed (integer change)	{		if (change & CHANGED_LINK)		{			if(gAv == llAvatarOnSitTarget())			{				llSensorRemove();				gSitting = TRUE;				vector LPos = (gPos-llGetPos())*llGetLocalRot();				UpdateSitTarget(LPos,gRot); 			}			else			{				gSitting = FALSE;			}		}	}}

I grabbed Strife's routine directly from the LSL wiki.  Hence the attribution.  It will need some polishing to make it pretty and to add any bells, whistles, and safeguards you need.  I just tested it in world, though, and it seems to work.  Just be sure to name your collision link "Tripwire" so that it's detected properly.

  • Like 1
Link to comment
Share on other sites

Hello Rolig, This is so awesome, thanks for helping me with this!  Would you have time for a quick question? 

I tried the script in the root prim and I end up at a wierd place on the map when I sit on it. It's 0,0,0 in world map coordinates. Is there something I can change?

Link to comment
Share on other sites

Ah... well...  that's a puzzle.  A more serious problem is that I set up the calculation for LPos without taking the rotation of the root prim into account, so it works fine for me until I turn the prim.  Then I get a wonky vector.  That's what I get for posting too quickly.  Let me poke at it more seriously after supper and see if I can post a better calculation.

  • Like 1
Link to comment
Share on other sites

NP.  It was a silly mistake.  I wanted to remove the effect of the prim's rotation, so I should have divided by llGetLocalRot() (or llGetRot()) instead of multiplying.  Same with the local rotation gRot.  So those two lines should read

            vector LPos = (gPos - llGetPos())/llGetRot();            UpdateSitTarget(LPos,gRot/llGetRot());

Like you, I get a bogus result every once in a while, although not one that has tossed me to the sim's garbage collector at <0,0,0>.  I'm not sure what causes that and I don't have the patience right now to figure it out.  As I said, this is a quick and dirty script that will need a bit of tuning before it does everything you want anyway. 

  • Like 1
Link to comment
Share on other sites


Gawain Galtier wrote:

It's working wonderfully! I will try to fine tune it as suggested. You're the best, and I really don't know how to thank you adequately. If you're ever in the market for a new friend, you have one in me!  Thank you thank you and wishing you an awesome weekend,

Gawain

Rolig is the best, and can't resist a good puzzle. Keep that weakness in mind.

;-).

  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3547 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...