Jump to content
You are about to reply to a thread that has been inactive for 1076 days.

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

Recommended Posts

Hello,

How do i loop the llSetKeyFrameMotion i am trying to script elevator which is meant to move from 0 to 500 m smooth moving but finding hard to make it reach there. its either going above 1000m or not.

 

here is the link was following the script.of course i was using the KFM_FORWARD

http://wiki.secondlife.com/wiki/User:Dora_Gustafson/Harmonic_Oscillator_motion

thank you.

 

Edited by devoscript
thank you
Link to post
Share on other sites

I don't understand why you are trying to loop anything at all, and I don't see why you are using Dora's harmonic oscillator for that application. An elevator moves in a straight line, up or down.  There's a limit on how far you can move with a single KFM step, so you need to make a series of steps to cover a long distance, but they're all in the same direction.  There's nothing loopy or oscillating about that.

Link to post
Share on other sites

Thanks for replying Rolig

you mean to say i can use steps one after one 

for example to reach at level of 100

llSetKeyframedMotion([<0.0, 0.0, 25.0>,  5,<0.0, 0.0, 0.0>,  5],[KFM_DATA, KFM_TRANSLATION, KFM_MODE, KFM_PING_FORWARD]);

llSetKeyframedMotion([<0.0, 0.0, 25.0>, 5,<0.0, 0.0, 0.0>, 5],[KFM_DATA, KFM_TRANSLATION, KFM_MODE, KFM_PING_FORWARD]);

llSetKeyframedMotion([<0.0, 0.0, 25.0>, 5,<0.0, 0.0, 0.0>, 5],[KFM_DATA, KFM_TRANSLATION, KFM_MODE, KFM_PING_FORWARD]);

llSetKeyframedMotion([<0.0, 0.0, 25.0>, 5,<0.0, 0.0, 0.0>, 5],[KFM_DATA, KFM_TRANSLATION, KFM_MODE, KFM_PING_FORWARD]);

Link to post
Share on other sites

Not quite. For one thing, there is no such thing as KFM_PING_FORWARD. And you don't need to specify KFM_FORWARD anyway.  That's the default.  More importantly, you don't need four separate function calls to complete one path.  You only need one.  Read http://wiki.secondlife.com/wiki/LlSetKeyframedMotion

llSetKeyframedMotion([<0.0, 0.0, 25.0>, 5,<0.0, 0.0, 0.0>, 5, <0.0, 0.0, 25.0>, 5,
<0.0, 0.0, 0.0>, 5, <0.0, 0.0, 25.0>, 5,<0.0, 0.0, 0.0>, 5, <0.0, 0.0, 25.0>, 5,<0.0, 0.0, 0.0>, 5],
[KFM_DATA, KFM_TRANSLATION]);

Or, more simply
 

integer i;
list lMove;
while (i < 4)
{
    lMove += [ <0.0,0.0,25.0>,5, ZERO_VECTOR,5];
    ++i;
}
llSetKeyframedMotion(lMove, [KFM_DATA, KFM_TRANSLATION]);

Either one makes the elevator move up 25m over 5 seconds, wait in place for 5 seconds, and move up another 25m .... over and over until it's reached 100m.

Edited by Rolig Loon
Link to post
Share on other sites

Of course.  I thought you wanted it to stop every 25m.  That's the way you wrote it. If you don't want them, just take them out.  In fact, if you are interested in a perfectly smooth, continuous motion without the gradual slowing that KFM can produce near the end of each path segment, you can break each segment a meter or so short of its end and then start a new one.  You'll have to do a little cleanup at the end of the final segment to get the elevator to stop at exactly the right elevation.  You can do that with a final calculated KFM step. Here's a quick example that takes four steps that are nominally 4.0m each but are interrupted 2.0m before they end, so they are actually roughly 2m segments. The final step is calculated to stop the elevator 8.0m above where it started.

integer target_id;
vector target_pos;
vector StartPos;
integer iStep;

default
{
    touch_start(integer total_number)
    {
        StartPos = llGetPos();
        llOwnerSay("Height = " + (string)StartPos.z);
        target_pos = llGetPos() + <0.0, 0.0, 4.0>;
        target_id = llTarget(target_pos, 2.0);
        llSetKeyframedMotion([<0.0,0.0,4.0>,5],[KFM_DATA,KFM_TRANSLATION]);
        iStep = 0;
    }
    at_target(integer tnum, vector targetpos, vector ourpos)
    {
        if (tnum == target_id)
        {
            ++iStep;
            llTargetRemove(target_id);
            llSetKeyframedMotion([],[]);
            vector Pos = llGetPos();
            llOwnerSay("Height = " + (string)Pos.z);
            if (iStep < 4)
            {
                target_pos = llGetPos() + <0.0, 0.0, 4.0>;
                target_id = llTarget(target_pos, 2.0);
                llSetKeyframedMotion([<0.0,0.0,4.0>,5],[KFM_DATA,KFM_TRANSLATION]);
            }
            else if (iStep == 4)
            {
                float Dist = StartPos.z + 8.0 - Pos.z;
                llSetKeyframedMotion([<0.0,0.0,Dist>,2.0] ,[KFM_DATA,KFM_TRANSLATION]);
            }                           
        }
    }        
}

EDIT:  BTW, This extra bit of smoothing is probably not necessary for your application.  I just added it to show that you can, in fact, smooth out any transitions between KFM segments if you wish.  Generally, though, you can do without it.

Edited by Rolig Loon
Link to post
Share on other sites
You are about to reply to a thread that has been inactive for 1076 days.

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...