Jump to content

Bobbing motion in child prim attachment


Bitsy Buccaneer
 Share

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

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

Recommended Posts

8 hours ago, OptimoMaximo said:

Your best bet is to animate the attachment joint, so that you can haveboth rotation and bobbing a the same time at way lower cost, computationally speaking.

How would I do that? You've gone well over my head once again, Optimo, and search isn't helping me understand it. A sort of wave motion would be cool, but that would be a later step and on a different version. (Happy to talk about it now though :)

For this one, I'd like it to just bob up and down without rotation.

45 minutes ago, Wulfie Reanimator said:

There is no function like llTargetOmega to smoothly move an attachment back and forth (You could do that with a rezzed object.), so you'll have to make a loop that moves the object up and down bit by bit.

What function(s) would be best to make that loop?

My scripting level is such that I can parse and adjust a fair number of functions in a working script, but I often get muddled trying to puzzle through the abstract descriptions in the wiki. I know it doesn't help that this is such a special case and I appreciate any advice.

Link to comment
Share on other sites

1 hour ago, Bitsy Buccaneer said:

How would I do that?

You can make an actual animation for just the interested attachment point, which is a bone in reality, and play that back with a script call. Important thing is also to have a reset position animation to go with. Scripting it makes the attachment point you choose irrelevant, while an animation, on the other hand, will be specific to that attachment point only. You can use Blender with Avastar to animate attachment points.

  • Thanks 1
Link to comment
Share on other sites

4 hours ago, Bitsy Buccaneer said:

What function(s) would be best to make that loop?

My scripting level is such that I can parse and adjust a fair number of functions in a working script, but I often get muddled trying to puzzle through the abstract descriptions in the wiki. I know it doesn't help that this is such a special case and I appreciate any advice.

I wrote a long explanation of the concepts involved, but I messed up and lost the whole thing, so I'm going to do a TLDR with some over-commented script that works as-is.

Things you need:

  • A loop and some kind of counter (like an integer variable) for how many loops have passed.
    Look up "for loop", "while loop" and "do-while loop" on the wiki. They all do basically the same thing, just pick the one you prefer.
  • llSetLinkPrimitiveParams to change the attachment's position without delay. The wiki page for that can be pretty overwhelming at first.
    Alternatively you could use llSetLocalPos, but it has a forced delay of 0.2 seconds after it, which can make it too slow.
  • llSleep to slow down the loop, otherwise the attachment will move erratically.

Here's a working example (it's simpler than it looks at a glance):

float   distance = 0.1; // How far (in meters) to move up/down.
float   time = 0.5; // How fast (in seconds) to move from top/bottom.
integer steps = 10; // How many steps to take between the top/bottom, more is smoother.

default
{
    state_entry()
    {
        // Convert the distance and time to a per-step value.
        // One pass of the loop is one step.
        distance = distance / steps;
        time = time / steps;
        
        while(TRUE) // Start an infinite loop that just repeats the up/down loops.
        {
            integer counter; // This counts how many steps have been taken.
            
            while(++counter <= steps) // Up loop, repeated by the amount of steps. (The ++ means "increment by one.")
            {
                // Move the object to its current location plus one step.
                llSetLinkPrimitiveParamsFast(LINK_ROOT, [PRIM_POS_LOCAL, llGetLocalPos() + <0, 0, distance>]);
                llSleep(time);
            }
            
            counter = 0; // Reset the step counter for the next loop.
            
            while(++counter <= steps) // Down loop, repeated by the amount of steps.
            {
                // Move the object to its current location plus one "negative" step (down).
                llSetLinkPrimitiveParamsFast(LINK_ROOT, [PRIM_POS_LOCAL, llGetLocalPos() + <0, 0, -distance>]);
                llSleep(time);
            }

            // Now the infinite loop repeats and the two loops start over.
        }
    }
}

One downside of this (infinite loop) method is that the script can't do literally anything else because it's busy in a loop that won't exit/stop.

One way to have a repeating loop like this without being stuck with it is to use llSetTimerEvent and do the up/down loops there. That way the script has a chance to be interrupted, but the bobbing will temporarily stop as well.  Another way is to use a separate script, or an actual animation like @OptimoMaximo is suggesting.

Edited by Wulfie Reanimator
  • Thanks 1
Link to comment
Share on other sites

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