Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Reduce avatar walking speed

Lynnore Vaher
Registered User
Join date: 19 Jul 2008
Posts: 16
05-25-2009 03:59
So i finally got at a point where i have to ask help through the forums, after making a whole web update server and more advanced things i now need to make a script to slow down movement speed. I thought it would be simple and got it working, it slows down movement.

But.. now comes the tweaking which has me confused, when i walk it seems that llSetForce moves me to the left or right while its not suppose to. Also when i stop walking (release the keys), it pushes me back a few meters at times so i tried with several ways to get that out of there but failed.

CODE

SCROLL DOWNNNNN!!! :P


So i have a few questions:
1. How could i minimize the push back when releasing the keys (when no longer moving)?
2. How can i make the movement smoother? Meaning no more choppy movement and reducing or fully taking away the push back on the sides when you just walk forward.
3. Any advice or know a better way to handle control keys, maybe more efficient or less lag?
4. I tried using llApplyImpulse but it seems way smoother with llSetForce, maybe i used it wrong? Any comments on this?

Thanks for reading!
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
Beats me...
05-25-2009 08:16
...but since nobody else has replied, I will chime in to keep the thread alive.

There are some/many scripts out there that do the opposite---the speed avatars up. Find one of those you like, and reverse whatever it does.

I notice that you always assume that FWD will be level, i.e., velocity.z==0. What if it is uphill? Should you adjust for that?
_____________________
So many monkeys, so little Shakespeare.
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
About the "push back"...
05-25-2009 08:22
This could be lag related. The server is authoritative about avatar position. Your viewer might be extrapolating where it will be, and when you release the arrow key, the viewer continues to move it a bit until the server sends back the message that says exactly where your avatar is stopped. Then, your viewer bounces it back.

This happens to me a lot becuase I have satellite, with 1.5 second ping times. My av often overshoots the stopping point, and then snaps back. (This is why I love double-click auto-pilot--see the Advanced menu 8-)
_____________________
So many monkeys, so little Shakespeare.
Lynnore Vaher
Registered User
Join date: 19 Jul 2008
Posts: 16
05-25-2009 08:50
Thanks for your replies, guess i can't do much against that then. But i have bigger problems now, for one i need to get the flight speed equal to the walking speed, limit jumping and tapping the keys make you get pushed forward for some reason.

But my current script is getting a mess, i am going to rewrite it and post it here again. Never worked with llSetForce or velocity or any other of those kind of functions.
Lynnore Vaher
Registered User
Join date: 19 Jul 2008
Posts: 16
05-25-2009 09:28
So this is how it looks now, still puzzled about the jumping and flying. Currently if you jump, you'll fly across half the sim. And nvm the tapping on keys, fixed once i cleaned up the script!

CODE

// Global Variables
float speed = 160; // Speed
float zPush = -5.0; // Force push down, up/down hill (might remove again)
key id = NULL_KEY; // Owner key

default
{

state_entry()
{
// Set force to zero, just in case
llSetForce(<0,0,0>, TRUE);

// Set the owner key
id = llGetOwner();

// Request permission to control keys
llRequestPermissions(id,PERMISSION_TAKE_CONTROLS );

}

run_time_permissions(integer perm)
{

if(perm & PERMISSION_TAKE_CONTROLS)
{

// We have permission to take controls, so take them!
llTakeControls (CONTROL_FWD|
CONTROL_BACK|
CONTROL_LEFT|
CONTROL_RIGHT|
CONTROL_UP|
CONTROL_DOWN,
TRUE,TRUE);

}

}

control(key av, integer level, integer edge)
{
// Local variables
vector force = ZERO_VECTOR; // Use the force!
integer d = llGetAgentInfo(id); // Agent stuff

if ( ( level & CONTROL_UP ) || ( edge & CONTROL_UP ) )
{
// braces here so the forum doesn't stretch lmao
force = force + <0,0,-speed>;
}
if ( ( level & CONTROL_DOWN ) || ( edge & CONTROL_DOWN ) )
{
// and here too
force = force + <0,0,-speed>;
}
if ( level & CONTROL_FWD ) force = force + <-speed,0,zPush>;
if ( level & CONTROL_BACK ) force = force + <speed,0,zPush>;
if ( level & CONTROL_LEFT ) force = force + <0,-speed,zPush>;
if ( level & CONTROL_RIGHT ) force = force + <0,speed,zPush>;

if(d & AGENT_ALWAYS_RUN)
{

// If wearer is running, double the force
// (needs tweaking later to match walking speed)
llSetForce(force*2 + <0.0,0.0,-10>, TRUE);

}
else if ( d & AGENT_IN_AIR )
{

// Limit flight and jumping

if ( d & AGENT_FLYING )
{

// flying

}
else
{

// jumpin!

}


}
else
{
// When walking
llSetForce(force, TRUE);

}

}

moving_end()
{
// At this moment (after a long time testing)
// the fastest way to stop the force
llSetForce(ZERO_VECTOR, TRUE);

}

}
Lynnore Vaher
Registered User
Join date: 19 Jul 2008
Posts: 16
05-25-2009 11:09
Okay fixed the push back, and flying and jumping by adding one thing! A simple move to target in the moving_end event. Thought about it when i read this

From: someone
This could be lag related. The server is authoritative about avatar position. Your viewer might be extrapolating where it will be, and when you release the arrow key, the viewer continues to move it a bit until the server sends back the message that says exactly where your avatar is stopped. Then, your viewer bounces it back.


So i figured why not just send a move to target to the position where the avi stopped. So then the server would know those coords and to the client it would seem like the move to target never happened. This also fixed jumping, and reduced flying to the same speed. So my script got allot shorter.

Thanks for the help ^^
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
05-25-2009 11:22
what about using llApplyImpulse?

i have a warp hud that moves me to my cam position, when i get to the target it applies an impulse negative of the velocity

llApplyImpulse(-llGetVel(),FALSE); you could probably play with that to slow down the walk. i did make a jump stopper in the past that set a negative z force whenever the avatar tried to jump, basically just took a super jumper and reversed the effect

edit: this seems to work

CODE

default
{
attach(key id)
{
if(id){llResetScript();}
}

state_entry()
{
llRequestPermissions(llGetOwner(),PERMISSION_TAKE_CONTROLS);
}

run_time_permissions(integer perm)
{
if(PERMISSION_TAKE_CONTROLS & perm)
{
llTakeControls(
CONTROL_FWD |
CONTROL_BACK |
CONTROL_LEFT |
CONTROL_RIGHT |
CONTROL_ROT_LEFT |
CONTROL_ROT_RIGHT |
CONTROL_UP |
CONTROL_DOWN |
CONTROL_LBUTTON |
CONTROL_ML_LBUTTON |
0, TRUE, TRUE);
}
}

control(key id, integer level, integer edge)
{
vector vel = llGetVel();
llApplyImpulse(-(vel*2),FALSE);
}
}
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
05-25-2009 11:50
lol, oops, i didn't read all of your first post, i just read the code you had posted
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Lynnore Vaher
Registered User
Join date: 19 Jul 2008
Posts: 16
05-25-2009 12:08
From: Ruthven Willenov
lol, oops, i didn't read all of your first post, i just read the code you had posted


That's okay! Love learning new stuff, didn't know you could do it that way and i will try that out too! That's going in my bikini too ^^

/me is at the beach with no rez on so she has all her scripts in the prim string of her bikini top.

lmao
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
05-25-2009 12:16
you'll wanna take the llOwnerSay out of there, i just had it in there for some debugging
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
05-25-2009 17:22
Note that jumping is a little different from walking, running, and flying. When you jump, there is one impulse applied to your avatar in the upward direction (discounting gravity, but I suspect you're not trying to counter gravity), whereas when you walk, run, or fly the system applies constant impulses/forces in an active manner. So when the UP or DOWN controls are pressed, you might want to test whether you are flying (llGetAgentInfo(llGetOwner())&AGENT_FLYING). If you are flying, go ahead and apply your force. If you are jumping (or falling I suppose), you might wait a short period to make sure the jump has started and then apply a small impulse downward instead.