Jump to content

Object needs to do 2 simultaneous motions - confused


Zara Avindar
 Share

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

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

Recommended Posts

Not my first rodeo scripting, but I don't do it enough to know the language that well. I'm trying to have an object raise 2 meters and turn 90 degrees while it's raising. So one smooth motion. The problem is that I don't really know what function I should be using to get it to do that. I have scripts that I use to raise things and to turn things, but to combine them is a separate problem that appears to require a different function then what I'm acquainted with. When I dig into the functions it's hard to find one that does what I want it to and it seems that I'm spending a lot of time just trying to figure out which function to use. I'd appreciate any help that anyone can give me to narrow down my search. Thank you in advance.

Link to comment
Share on other sites

23 minutes ago, Zara Avindar said:

I looked at llSetKeyframedMotion, but it seemed to me that it was for something that was moving across the sim. This object is a machine that only needs to do this one motion and then return to it's original position. Like a turning hydraulic lift.

Exactly.  You can use it for pendulums (see Dora's example), slow-rotating doors, and all sorts of local movements.

Link to comment
Share on other sites

well, here is a way to do this:

float height;
float new_height;
float inc_height = 2.0;
float inc_eul_rot = 1.57080;


default
{
    state_entry()
    {
    }

    touch_start(integer total_number)
    {
        float step_h = inc_height / 100;
        float step_r = inc_eul_rot / 100;
        vector h = llGetPos();
        height = h.z;
        new_height = height + inc_height;
        rotation rot = llGetRot();
        while (height < new_height)
        {            
            llSetLinkPrimitiveParamsFast(0,[PRIM_POSITION,(llGetPos()+ <0,0,step_h>), PRIM_ROTATION,llEuler2Rot( llRot2Euler(llGetRot())+<0,0,step_r>)]);
            height = height + step_h;
            llSleep(0.002);
        }
    }
}

pls let me know if this is what you mean,

enjoy,

Dargo

Edited by Kardargo Adamczyk
changed height cacluation to add step_h instead of 0,02
Link to comment
Share on other sites

And here's a way to do it using KFM:

vector TARGET_POS_LOCAL = <0.0, 0.0, 2.0>; //the distance to move
vector TARGET_ROT_LOCAL = <0.0, 0.0, 90.0>; //the angle to rotate, degrees
float duration = 2.5; //the time to take

float direction = 1.0;
integer active;
vector start_pos;
vector start_rot;

default
{
    touch_end (integer count)
    {
        if (!active)
        {
            //save the start pos and rot for use in the sanity check later
            start_pos = llGetPos ();
            start_rot = llRot2Euler (llGetRot ());

            llSetKeyframedMotion
            ([
                TARGET_POS_LOCAL * direction,
                llEuler2Rot (TARGET_ROT_LOCAL * direction * DEG_TO_RAD), 
                duration
            ], []);

            //set the timer to clean up after the KFM
            llSetTimerEvent (duration);
            active = TRUE;
        }
    }

    timer ()
    {
        llSetTimerEvent (0.0);

        //now for a sanity check: stop the KFM and set the object to the 
        //actual target in case KFM didn't quite get it right
        llSetKeyframedMotion ([], [KFM_COMMAND, KFM_CMD_STOP]);
        llSetRegionPos (start_pos + (TARGET_POS_LOCAL * direction));
        llSetRot (llEuler2Rot (start_rot + (TARGET_ROT_LOCAL * direction * DEG_TO_RAD)));

        active = FALSE;
        direction = -direction;
    }
}

Ok, so I'm only stumbling my way through KFM, It's not something I've done very much of. This is primarily an example so people can compare KFM with stepped motion.

Link to comment
Share on other sites

Keyframed motion is good for this.

Notes:

  • Keyframed motion works on an entire link set, not individual child prims.
  • Keyframe motion remains smooth even in overloaded sims. Other methods get jerky when script execution is below 100%.
  • Forward and reverse keyframed motion is not entirely accurate or reliable. After completion,  you have to check to see if you' arrived at the desired destination. There will be some error. Larger error in overloaded sims.
  • You can do simultaneous translation and rotation with keyframed motion, but they won't sync perfectly. I tried to build a spiral escalator once, which required a screw-type motion, and it almost worked. Every few seconds there was a jerk when rotation and translation happened out of sync. That may not be a problem for a garage-type lift, unless the motion has to be synchronized exactly.
  • Normalize your quaternions. Don't use llRotateBetween to make precise quaternions; it's buggy. See the wiki.
Link to comment
Share on other sites

Thanks Dargo! He came and looked at what I'm doing and it makes sense to make this as simple as possible. I'm going to make the linked set a single mesh object, (which was my intention from the beginning). Once that is done, I should be able to use his simple script to make it work the way I need to. Thank you to everyone for their input and help. This is such a great forum! :D

Link to comment
Share on other sites

just adding to the conversation about key framed motion

when the path is static, meaning that it doesn't change at runtime once determined, then we can get a little bit more efficient  by creating the KFM list one time in state_entry

when we use key framed motion a lot in our scripts, then we can script up a general purpose key framed motion list generator. Which dumps the formatted KFM list to chat. From where we can copy paste the list into our runtime scripts

  • Like 1
Link to comment
Share on other sites

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