Jump to content

Slowed Avatar Movement.


TessaAnnaMarie
 Share

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

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

Recommended Posts

I am working on creating a script to slow/speed up avatar movement. 

This is what I have so far. 

 

float IMPULSE = 2.7;


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

    touch_start(integer total_number)
    {
        llSay(0, "Touched.");
        llStopMoveToTarget();
    }
    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 ,
                            TRUE, TRUE);
                           
        }
    }

    control(key id, integer level, integer edge)
    {
        vector v;
        if (level & CONTROL_FWD)
            v.x = -IMPULSE;
        else if (level & CONTROL_BACK)
            v.x = IMPULSE;
        else if (level & CONTROL_LEFT)
            v.y = -IMPULSE;
        else if (level & CONTROL_RIGHT)
            v.y = IMPULSE;
        llApplyImpulse(v, TRUE);
    } 
    
}

 

 

This seems to work as attended. Nearly perfectly. Couple of small issues though. 

1. If I raise the number above 3 when I try to walk backwards (Down arrow / "S") it will not turn my avatar around, the animation is walking forwards while the avatar is moving backwards. Any fix to this?

2. If i press my "Space bar" it will revert back to normal movement speed for as long as i hold the space bar and send me in the opposite direction (If I'm Holding "W" and click space, i will speed up and go backwards). This is my bigger issue that i need to fix, as this is just "breaking" everything I'm trying to do with the script. 

 

Note: either of these issues only happen when i go positive with the IMPULSE variable (Or slow down), if i speed up, i don't have these issues. 

 

 

If there is a better way to do what I'm trying to do, please let me know. Been working on this for weeks. This is the closest i have gotten. 

Link to comment
Share on other sites

have a read of this thread here.  The avatar walking speed is approx. 3.2 meters a second

when we apply too much impulse then this can turn the positive walking speed value into a reverse value and the result can be difficult to interpret

basically we should try to limit our walking speed - impulse to a number when reversed is not less than 0

also as the region server load can lag at times, and individual user ping times are variable we need be conservative in how much impulse can be applied in the widest number of use cases

Edited by elleevelyn
Link to comment
Share on other sites

The two main methods of doing this are to apply a reverse force in the direction of intended movement, or to override movement entirely and move with one of several physics functions (llMoveToTarget, llSetForce, llSetVel) in such a way as to aquire the desired speed. 

With a reverse force, you have to account for various cases that can cause an undesired effect (jumping, crouch-walking & falling off the top of my head) if not handled carefully.

With overriding movement directly, the special cases are less of a concern, but you lose some special magic that allows the avatar to walk over small bumps. You can fix that problem with applying a small anti-gravity force while walking, but that causes the avatar to walk into the air in some severely physics-lagged regions. Fixes for airwalking work some of the time but are hit or miss.

I have some example scripts in the LSL library section:

 

  • Like 1
Link to comment
Share on other sites

9 hours ago, TessaAnnaMarie said:

1. If I raise the number above 3 when I try to walk backwards (Down arrow / "S") it will not turn my avatar around, the animation is walking forwards while the avatar is moving backwards. Any fix to this?

Backwards turning behavior is different depending on whether your AO overrides your walking animation with llSetAnimationOverride; An animation overridden avatar will face backwards when walking backwards, but can be bugged out by scripted  forces.

9 hours ago, TessaAnnaMarie said:

2. If i press my "Space bar" it will revert back to normal movement speed for as long as i hold the space bar and send me in the opposite direction (If I'm Holding "W" and click space, i will speed up and go backwards). This is my bigger issue that i need to fix, as this is just "breaking" everything I'm trying to do with the script.

I think overriding the movement directly (second method of previous post) is the only way to not have that specific issue. Why would you move while holding your space-bar though?

Edited by Quistess Alpha
Link to comment
Share on other sites

Space is by default mapped to "stop moving", so by holding it you're suppressing your normal avatar movement. The script isn't and can't be aware of this since it's watching your control inputs directly (stop moving is not a control you can hook), so only the scripted impulses apply.

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

1 hour ago, Frionil Fang said:

Space is by default mapped to "stop moving", so by holding it you're suppressing your normal avatar movement.

An interesting feature/bug I found when testing it (without my usual scripted movement control on) is that if you begin to hold down space while already walking forward (and continue holding both space and forward), you never come to a complete stop, but continue walking at slow speed. However, if you try to start walking (from a stop) while space is held, then you're stuck in place.

Edited by Quistess Alpha
Link to comment
Share on other sites

2 minutes ago, Quistess Alpha said:

An interesting feature/bug I found when testing it (without my usual scripted movement control on) is that if you begin to hold down space while already walking forward, you never come to a complete stop, but continue walking at slow speed, but if you try to start walking while space is held, then you're stuck in place.

Thanks for all the input will look over your way of doing it and see if that works for me. 

As for why walking while holding space, its not the intention. I'm working on creating a combat game that can hinder movement, most things are scripted out and working but wanted to tackle this monster. So its important for me to not have a way for players to over-ride it as simple as pressing the space bar. next monster to tackle is a "You can't move at all" feature, so still al long way to go. 

Link to comment
Share on other sites

2 minutes ago, TessaAnnaMarie said:

As for why walking while holding space, its not the intention. I'm working on creating a combat game that can hinder movement, most things are scripted out and working but wanted to tackle this monster. So its important for me to not have a way for players to over-ride it as simple as pressing the space bar. next monster to tackle is a "You can't move at all" feature, so still al long way to go. 

Sticking (forced no-movement) someone can be as simple as llTakeControls(0x337,TRUE,FALSE); while doing nothing in the control event, but to be antagonistic to attempts to unstick oneself via another script, you might want to try llMoveToTarget(llGetPos(),0.05); to stick, llStopMoveToTarget() to un-stick.

Link to comment
Share on other sites

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