Sign in to follow this  
Restless Swords

LSL inside attachment to SLOW walk speed?

Recommended Posts

I have an object that will be worn (attached).  an example (NOT what I am doing) would be crutches.  When worn, can their script slow down the actual SPEED (distance covered) during a walk?  not the animation, the actual movement speed.  I know an alternative would be to create some sort of vehicle that moved (slowly) but would like to keep this as a worn attachment.

 

Share this post


Link to post
Share on other sites
Posted (edited)

I'd play around with either llApplyImpulse(< -n,  0.0,0.0>,,TRUE) or llSetForce(-< -n,  0.0,0.0>, TRUE) in the control event, using different values for n until you find something appropriate.  I made something years ago that does this.   I'll try to dig it out tomorrow and see how I did it back then..   

Note that you'll need a special animation to get this to work, though, otherwise the user's feet will be sliding about, since walking animations usually assume the default SL forward walking pace of 3.2 metres/second

Edited by Innula Zenovka
  • Like 2

Share this post


Link to post
Share on other sites
Posted (edited)

Maybe something like...

 

float meters_per_second = 3.2; // change this to set max speed of avatar


//--------------------------------------------------------------------------------

float step;

vector pos;

key attacher;

default
{

	state_entry()
	{

		step = meters_per_second * 0.1;

	}
	
	attach(key attach_id)
	{
		
		if(attach_id != NULL_KEY && llGetAttached() > 0)
		{
			pos = llGetPos();
			attacher = attach_id;
			llSetTimerEvent(0.1);
		}

	}

	timer()
	{

		vector current_pos = llGetPos();

		if( llVecDist(current_pos, pos) > step )
		{

			integer agent_info = llGetAgentInfo();

			if( (agent_info & AGENT_WALKING) || (agent_info & AGENT_ALWAYS_RUN) )
			{

				vector direction = current_pos - pos;

				if(direction.x > step)
					direction.x = step;
				else if(direction.x < -step)
					direction.x = -step;

				if(direction.y > step)
					direction.y = step;
				else if(direction.y < -step)
					direction.y = -step;

				if(direction.z > step)
					direction.z = step;
				else if(direction.z < -step)
					direction.z = -step;


				pos += direction;

				llSetLinkPrimitiveParamsFast(0, [PRIM_POSITION, pos]);

			}

			else
				pos = llGetPos();

		}

		else
			pos = llGetPos();

	}


}

 

Keep in mind that this does not account for agents crossing sim/region boundaries, and may cause a jerking motion when they're corrected; it's a decent example albeit written from scratch, so I have no idea about how compile-able it is.

Edited by AlduousMcBurlington
  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, AlduousMcBurlington said:

llSetLinkPrimitiveParamsFast(0, [PRIM_POSITION, pos]);

Won't this only work if you are sitting on it, and it is non-physical? 

  • Like 1

Share this post


Link to post
Share on other sites
7 hours ago, Innula Zenovka said:

I'd play around with either llApplyImpulse(< -n,  0.0,0.0>,,TRUE) or llSetForce(-< -n,  0.0,0.0>, TRUE) in the control event, using different values for n until you find something appropriate.  I made something years ago that does this.   I'll try to dig it out tomorrow and see how I did it back then..   

Note that you'll need a special animation to get this to work, though, otherwise the user's feet will be sliding about, since walking animations usually assume the default SL forward walking pace of 3.2 metres/second

I like these approaches, like a "flight feather" but opposite.

Share this post


Link to post
Share on other sites
Posted (edited)

Alduous, I think your suggestion would move the box/item attached to my avatar only if I was sitting on the box, not if I wear it as an attachment?

- and then the agent would never be WALKING, just SITTING? ---- unless there is something I am totally missing

Edited by Restless Swords

Share this post


Link to post
Share on other sites

So far it seems that everyone is in consensus that there is no way to alter the SL default walk speed (3.2 m/s) ?

- what a shame, I might have to resort to using the 'sit' vehicle approach and new custom animations, which I really wanted to avoid

Share this post


Link to post
Share on other sites
3 minutes ago, Restless Swords said:

Aldus, I think your suggestion would move the box/item attached to my avatar only if I was sitting on the box, not if I wear it as an attachment?

- and then the agent would never be WALKING, just SITTING? ---- unless there is something I am totally missing

No, that ought to work in an attachment too.  I think you're right that it will not look like walking, though, unless you also trigger an animation whenever you move forward.  That would certainly be true if you used this approach in an object that you sit on instead of an attachment.

Share this post


Link to post
Share on other sites
8 minutes ago, Rolig Loon said:

No, that ought to work in an attachment too.  I think you're right that it will not look like walking, though, unless you also trigger an animation whenever you move forward.  That would certainly be true if you used this approach in an object that you sit on instead of an attachment.

Hmmm, would not the standard SL WALK animation be running?

- I can understand it might look funny ('sliding' slightly backwards) since the forward distance would no longer be the normal 3.2 m/s

- If I have to create and play my own WALK animation, I am almost back to going with the sit-on-vehicle and doing my own movement and animation

Share this post


Link to post
Share on other sites

Tried it, without success.

1) when the attachment box was LSL moved, it hopped up a couple of meters in the air, above the avatar bounding box

2) no movement of the attachment box had any affect on the avatar

Share this post


Link to post
Share on other sites

Oh, well.  Worth a try.  ¬¬  On reflection, that should have been obvious, since any command like llSetPos, SLPPF with PRIM_POS, or llMoveToTarget is going to move the attachment, not the avatar.  So, Innula's suggestion is probably the best one. Try llApplyImpulse.

Share this post


Link to post
Share on other sites

Actually, since the avatar is physical, I would think that replacing llSLPPF with llMoveToTarget(pos, 0.09); should actually work.

But this is, again, me talking out of my hat.

Share this post


Link to post
Share on other sites

llMoveToTarget called in an attachment will move the wearer, certainly.    A lot of collars use it.   It's really a matter of playing round with llApplyImpulse, llSetForce and llMoveToTarget and seeing which works best for the particular use-case.    I have a bit of difficulty visualising how best to use llMoveToTarget if you're simply trying to slow the avatar down, though, since you don't actually want to move the avatar anywhere.  You want to make it more difficult for her to move forwards, which isn't the same thing.   How do I calculate the target, and what happens when I get there?

Share this post


Link to post
Share on other sites
5 hours ago, Innula Zenovka said:

llMoveToTarget called in an attachment will move the wearer, certainly.    A lot of collars use it.   It's really a matter of playing round with llApplyImpulse, llSetForce and llMoveToTarget and seeing which works best for the particular use-case.    I have a bit of difficulty visualising how best to use llMoveToTarget if you're simply trying to slow the avatar down, though, since you don't actually want to move the avatar anywhere.  You want to make it more difficult for her to move forwards, which isn't the same thing.   How do I calculate the target, and what happens when I get there?

I haven't tried this, but the thought in my head when I suggested llMoveToTarget earlier in this thread was that you set a target that is, say, 3.2 m in front of your current position and tell llMoveToTarget to get there in 2.0 seconds instead of 1.0.  Then you run a timer that does a llStopMoveToTarget in 1.0 seconds and re-initiate the llMoveToTarget with a new target if the control event is still receiving a signal from your keyboard forward arrow.  I think you could leapfrog ahead like that effectively.  My hesitancy, on later reflection, was because I had not tried it yet and began doubting whether the attachment would in fact move the avatar.  You know much more about collars that I do, Innula, so you've restored my confidence.  ;)

I have no idea whether that's a sensible use of server resources, of course.

Share this post


Link to post
Share on other sites

It's used in a collar to constrain movement, to force the wearer to a specific spot and stop her moving away from it, or to make her follow the person holding her leash.      It's also used in hug/kiss attachments to get the hugger and huggee close enough to each other.  

I can see how it could be used to affect movement speed but it just seems to me that llApplyImpulse and llSetForce are going to far simpler to use if you  want only to slow down (or speed up) the avatar's normal walking pace.   You''re not interested in where the avatar wants to get to; after all; you want only to make it more difficult to move in that direction.   So you need only to set the second parameter, LOCAL, to TRUE and specify the vector (<-n,0.0,0.0>) and the simulator does all the calculations for you.

As a general rule, though, attachments, including HUDS, can use any of the physics movement functions to move the wearer about  (avatars are physics-enabled, but not change her rotation (unless RLV is involved.   Non-physical movement functions move the attachment, not the avatar.   

Share this post


Link to post
Share on other sites
Posted (edited)

in your control event...

  if(level & CONTROL_FWD)
        {
            if(llGetAgentInfo(llGetOwner()) & AGENT_WALKING )  
            { llApplyImpulse(<-8.0,0,0>,TRUE);            
            }
        }

Negative values greater than -7 or -8 will make you drift a bit mebbe?

 

Edited by Xiija
edit

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this