Jump to content

Smooth Bobbing(and possibly rotating)


Runeknight Hax
 Share

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

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

Recommended Posts

I've been looking for a way to script something which will allow me to simulate a smooth sort of bobbing motion in an object on the vertical axis. I've seen such things in the past but when I've asked as to the function that allowed it all I got was "it involves complicated trigonometry, you wouldn't get it." The examples I've seen which simulate what I'm interested in used a root stationary prim and a child prim within it that moved in either an up and down motion while rotating or a smooth elliptical pattern, and also could do so while being worn in an attachment slot.

I've tried the usual llsetpos and lltargetomega to no avail. I've also tried keyframes, hoverheight, and buoyancy but they only work with physical and/or unworn things. Trying to get the smooth fluidity with stepped movement calls just looks jittery and is prone to errors and also eats up resources.

I know it's possible to accomplish what I want but nobody seems to be privy to sharing how it's done, as scripts are held as private property and such.


One other thing I've been looking for is a way in which to rotate an object over 360 degrees and have it stop at a predefined angle smoothly, such as a clocks hand's spinning out of control then stopping on a certain time.
 It would be cool if this was possible as well.

Link to comment
Share on other sites

no no, I've selected the object and it stopped moving while it was selected. I've seen things like this since 2 or 3 years ago, on a weapon someone was wearing and a cube thing someone else had built. One of them was a gun that while in the holstered position floated in an eliptical motion next to their hip and the other was a rotating cube that bobbed up and down inside an invisible root prim.

Link to comment
Share on other sites


Runeknight Hax wrote:

no no, I've selected the object and it stopped moving while it was selected. I've seen things like this since 2 or 3 years ago, on a weapon someone was wearing and a cube thing someone else had built. One of them was a gun that while in the holstered position floated in an eliptical motion next to their hip and the other was a rotating cube that bobbed up and down inside an invisible root prim.

In that case, Dora's probably right.  It's a combinatiion of llTargetOmega and llSetPos or llSetRot.  That's a good way of making smooth rotating doors, for example..The giveaway is that you said it stops if you select it.  A client-side effect like llTargetOmega will do that.

Link to comment
Share on other sites

default{    state_entry()   {        llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]); // for non mesh aware viewers        llSetKeyframedMotion(            [<0.0, 0.0, 0.5>, llEuler2Rot(<0, 0, 180> * DEG_TO_RAD), 2,             <0.0, 0.0,-0.5>, llEuler2Rot(<0, 0, 180> * DEG_TO_RAD), 2],            [KFM_MODE, KFM_LOOP]);    }}

I think this will give you the motion you desire. It seems to hiccup on the first cycle through, then runs smoothly thereater. The first frame moves the prim up (Z-axis) a half meter from it's rezzed position, and turns it 180 degrees along the Z-axis. The second frame moves it down a half meter from the rezzed position and turns it another 180 degrees. It's set to loop indefinitely, giving you the bobbing motion I saw on the sim you mentioned. If you want a more realistic (sinusoidal) bobbing motion, you'd create more frames with the Z-axis offsets pulled from a table of sines (or computed in your code) and the Z-axis rotation divided into smaller pieces (360 degrees/# of frames).

Link to comment
Share on other sites

integer time = 0;integer attached = 0;integer animationLength = 20; // number of steps in the linear motioninteger animationCount = 0; // current position in the animationinteger animationDirection = 1; // 1 = forward, -1 = reversedefault{    state_entry(){    }    attach(key id){        attached=0;        animationCount = 0;        animationDirection = 1;                if(id){            attached=1;            llTargetOmega(<0,0,1>,1,1); // start it spinning            llSetTimerEvent(0.1); // 10 movements/sec            llOwnerSay("Attached");        }        else{            llSetTimerEvent(0);        }    }        timer(){        if(attached){            animationCount += animationDirection;            if(animationCount>=animationLength){ // go forward to end,then reverse            animationDirection=-1;            }            else if(animationCount<0){             animationCount=0;             animationDirection=1;            }            llSetPos(<0,0,animationCount*0.01>); // convert animation count into a position offset and move the prim        }    }}

 Place the above script in the child prim of a two-prim thing to wear. It's choppy, but gives the motion you described, and moves with the avatar. I don't know of a way to do this smoothly while being worn. I'll send you a test object (two cubes) in-world. It's probably pretty laggy as well.

Link to comment
Share on other sites


Runeknight Hax wrote:

It's not that smooth or fast but it works for what I need so I'll see what I can do with the script. Thanks! Now I need a way to rotate on an axis over 360 degrees and stop at a defined angle.

If you are trying to make a wrist watch that spins out of control, then stops at a certain time, I think you might just use a fast llTargetOmega call to spin it (possibly using a motion blurred hand texture), then issue llTargetOmega(<0,0,0>0,0) to stop it (and replace the texture with a crisp hand texture), followed immediately by a llSetRot to put the hand in the position you want. That might happen so fast that your eye won't notice that the hand was in some random position (when llTargetOmega stopped) before snapping to the desired time. You could also put a motion blurred hand texture on an always rotating prim that obscures the hand that's got the desired time. Make that prim transparent at the moment you wish to reveal the stationary hand.

Link to comment
Share on other sites

can take Maddy's script and apply to more than one object

if you got two of them then can mod so they step over/thru each other. and as they step along the wave you flip the transparency so the leading one flip full opaque and the second one fades. can do that part in a timer. stop the first one - move the second. stop the second - move the first. and so on

 

if get 3 or 4 or 5 or 6 working together then can create a long trail blur effect as you like

  

Link to comment
Share on other sites

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