Jump to content

Rotating Drum


naughtyniece
 Share

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

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

Recommended Posts

Hi, i would like some help from the helpful masses please :)

I have a prim (cylinder) that i would like to spin and then let slowly stop, like a tombola wheel or similar.

I have the code i need to spin it on its x Axis, but struggling to make it spin then slow and stop, tried for - next and do while and also timer, all to no avail.

rotation rot;
 
default
{
    state_entry()
    {
		vector xyz = <60,0,0>
        vector rads = xyz*DEG_TO_RAD;
        rot = llEuler2Rot(rads);
    }
   touch_start(integer s)
    {
        llSetRot(llGetRot()*rot);
    }

so i would like to touch and then let it spin maybe for 30 seconds and then stop, at which point i can then calculate where it has stopped using the angle it stopped at.

Its just the spinning , slowing and stopping i can't work out

Much thanks

 

Suzie

 

Link to comment
Share on other sites

 

Check out llTargetOmega(). This actually starts/stops an object rotating (viewer side only). Whereas, with llSetRot(), you would have to call it once for each partial rotation, on a timer - and that won’t be smooth.

Basically, you would need 3 timer states for llTargetOmega() to be called for starting, slowing, and stopping. I think you can’t have it “progressively slow down” using this method, just multiple speeds.

Someone else may have other advice!

Edited by Love Zhaoying
Originally said llSetLocalRot oops
  • Like 1
Link to comment
Share on other sites

Thanks, but i cannot see any difference, and the second life help on llSetLocalRot doesn't explain much. How would i start/stop this rotating, now that it is using localrot?

 

Sorry if i am being a bit dumb, but this is new to me, moving, sizing, hiding prims etc i can do but starting one rotating and then letting it stop.... no idea.

  • Thanks 1
Link to comment
Share on other sites

3 minutes ago, naughtyniece said:

Thanks, but i cannot see any difference, and the second life help on llSetLocalRot doesn't explain much. How would i start/stop this rotating, now that it is using localrot?

 

Sorry if i am being a bit dumb, but this is new to me, moving, sizing, hiding prims etc i can do but starting one rotating and then letting it stop.... no idea.

See where I corrected my post, I meant llTargetOmega, not llSetLocalRot.

Edited by Love Zhaoying
  • Like 1
Link to comment
Share on other sites

I think one drawback is, the thing you’re rotating can’t be attached to the thing it is resting on. Just “resting on it”/“rezzed on it”. Or, the entire object/impulse would rotate.

Perhaps someone will suggest giving it a rotational impulse, but again I think it would need to have “bearings”/axle and not actually part of a linkset (or the entire thing gets the impulse).

Link to comment
Share on other sites

Love is right, you can't script your spinning drum to slow down gradually.  The only solution I can imagine is pretty chancy.  You'd have to make your drum physical, apply a rotational impulse (with llAppyRotationalImpulse) , and let it gradually slow down by friction.  I can't think of a good way to control the rate of slowing, or a reliable way to keep the drum from wandering at least a little bit, though, so this is far from a good solution.

As far as starting and stopping llTargetOmega, however, Love has given you all the right information.  Take a look in the LSL wiki for details.

Link to comment
Share on other sites

Hi,

It is 'sat in' but not attached to another prim, just looks like it is, a sort of housing if you like. Imagine that big wheel on price is right or similar.

Then user will touch and it will spin fr a while, then after x slow down and then stop. I have got it rotating using llTargetOmega... just fiddling.. 

thanks for your help so far

Link to comment
Share on other sites

4 minutes ago, Love Zhaoying said:

I think one drawback is, the thing you’re rotating can’t be attached to the thing it is resting on. Just “resting on it”/“rezzed on it”. Or, the entire object/impulse would rotate.

Not an issue, as long as the script is in the child prim that is actually rotating. The entire linkset will only rotate if you put llTargetOmega in the root.

  • Thanks 1
Link to comment
Share on other sites

2 minutes ago, Rolig Loon said:

Love is right, you can't script your spinning drum to slow down gradually.  The only solution I can imagine is pretty chancy.  You'd have to make your drum physical, apply a rotational impulse (with llAppyRotationalImpulse) , and let it gradually slow down by friction.  I can't think of a good way to control the rate of slowing, or a reliable way to keep the drum from wandering at least a little bit, though, so this is far from a good solution.

As far as starting and stopping llTargetOmega, however, Love has given you all the right information.  Take a look in the LSL wiki for details.

Thanks, I knew it had to be physical for one scenario.

Link to comment
Share on other sites

Hi All,

Ok, i had a bit of a mess and this works, it may not be 'b the book' but it does the job

 

integer speed;

default
{
    state_entry()
    {
        llTargetOmega(llRot2Up(llGetLocalRot()), 0, 1.0);
    }    

    touch_start(integer total_number)
    {
       speed = 4;
       do 
       {
           llTargetOmega(llRot2Up(llGetLocalRot()), PI * speed, 1.0);
           llSleep(3.0);
        }
       while (--speed > 0);
       
       
        llTargetOmega(llRot2Up(llGetLocalRot()), 0, 1.0);
    }
    
}

of course i will accept and 'tweaks'

  • Thanks 1
Link to comment
Share on other sites

One more questionon this....

how do i know what the rotation is when it stops.... with LLlocal and llGet i could use something like

 rotation faceup = llGetLocalRot();
 llOwnerSay((string)faceup.x;

But that gives the same value for X, Y and Z wherever it stops.....?

thanks, this has been most helpful, and another ticked box in my sl scripting.

Link to comment
Share on other sites

13 minutes ago, naughtyniece said:

One more questionon this....

how do i know what the rotation is when it stops.... with LLlocal and llGet i could use something like


 rotation faceup = llGetLocalRot();
 llOwnerSay((string)faceup.x;

But that gives the same value for X, Y and Z wherever it stops.....?

thanks, this has been most helpful, and another ticked box in my sl scripting.

It will technically maybe go back to the original rotation. Technically, the rotation does not actually change - It is “viewer side only” - the server won’t know. Try and see. You could just set Rot when done, if I’m wrong.

@Rolig Loon, did I get it right?

Edited by Love Zhaoying
  • Like 1
Link to comment
Share on other sites

Hi,

Ok i have a complete code, that rotates a drum with 6 segments on the face of it (like a rolling dice) then slows ans stops and sets to one of the six posiitons.

It's not over complicated and actually the way it jerks into position, is quite pleasant.

Thank you to Love and Rolig for their input, and enabling me to make a rolling tumbler dice for my game. Much pleased, ta

integer speed;
rotation rot_xyzq;

default
{
    state_entry()
    {
        llTargetOmega(llRot2Up(llGetLocalRot()), 0, 1.0);
    }    

    touch_start(integer total_number)
    {
       speed = 4;
       do 
       {
           llTargetOmega(llRot2Up(llGetLocalRot()), PI * speed, 1.0);
           llSleep(llFrand(3));
        }
       while (--speed > 0);
              
        llTargetOmega(llRot2Up(llGetLocalRot()), 0, 1.0);
        integer faceup = (integer)llFrand(6)*60;
        vector xyz_angles = <faceup,0,0>;
        vector angles_in_radians = xyz_angles*DEG_TO_RAD;
        rot_xyzq = llEuler2Rot(angles_in_radians);
        llSetLocalRot(llGetLocalRot()*rot_xyzq);
        
        //Just saying this out so i can check its working, will use as variable
        llOwnerSay((string)rot_xyzq.x);
    }
    
}

Thank you so much

 

Suzie

  • Thanks 1
Link to comment
Share on other sites

4 minutes ago, naughtyniece said:

Hi,

Ok i have a complete code, that rotates a drum with 6 segments on the face of it (like a rolling dice) then slows ans stops and sets to one of the six posiitons.

It's not over complicated and actually the way it jerks into position, is quite pleasant.

Thank you to Love and Rolig for their input, and enabling me to make a rolling tumbler dice for my game. Much pleased, ta


integer speed;
rotation rot_xyzq;

default
{
    state_entry()
    {
        llTargetOmega(llRot2Up(llGetLocalRot()), 0, 1.0);
    }    

    touch_start(integer total_number)
    {
       speed = 4;
       do 
       {
           llTargetOmega(llRot2Up(llGetLocalRot()), PI * speed, 1.0);
           llSleep(llFrand(3));
        }
       while (--speed > 0);
              
        llTargetOmega(llRot2Up(llGetLocalRot()), 0, 1.0);
        integer faceup = (integer)llFrand(6)*60;
        vector xyz_angles = <faceup,0,0>;
        vector angles_in_radians = xyz_angles*DEG_TO_RAD;
        rot_xyzq = llEuler2Rot(angles_in_radians);
        llSetLocalRot(llGetLocalRot()*rot_xyzq);
        
        //Just saying this out so i can check its working, will use as variable
        llOwnerSay((string)rot_xyzq.x);
    }
    
}

Thank you so much

 

Suzie

You could think of the “jerky stop” as “locking into place”.

Link to comment
Share on other sites

4 minutes ago, naughtyniece said:

Ok i have a complete code, that rotates a drum with 6 segments on the face of it (like a rolling dice) then slows ans stops and sets to one of the six posiitons.

Aha!  I should have put 1 + 1 together and realized that you were still talking about your rolling dice project. In that case, the answer is much simpler. You don't need to script the rotating drum part at all.  Just make the die physical and drop/throw it on the floor.  It will tumble around for a little while and eventually stop, with one of its flat faces pointing up, just like a real die in RL.  That one's been done many times in SL, and is quite effective. B|

  • Like 1
Link to comment
Share on other sites

Yes, but i have a limited space and don't want to be be using DIE() when dice get thrown around, and fancied having a tumbling wheel as part of the game, so its all very eat and compact.I do have dice i can throw and thanks to help get the face up values, but people do tend to thrown them away lol.

  • Like 1
Link to comment
Share on other sites

Hello again, I am a little confused about rotation angles, can you help me?

This is the simplified code for my trolling drum, which is lovely and smooth, and look great.

integer speed;
rotation rot_xyzq;

default
{
    state_entry()
    {
        llTargetOmega(llRot2Up(llGetLocalRot()), 0, 1.0);
    }    

    touch_start(integer total_number)
    {
       speed = 4;
       
       do 
       {
           llTargetOmega(llRot2Up(llGetLocalRot()), PI * speed, 1.0); // spin at speed
           llSleep(llFrand(3));
        }
       while (--speed > 0);
              
        llTargetOmega(llRot2Up(llGetLocalRot()), 0, 1.0); //stop spinning
        //What is the Rotaton of the cylinder in DEGREES???
        rot_xyzq = llGetLocalRot();
       
        vector euler = llRot2Euler(rot_xyzq);
        euler *= RAD_TO_DEG;
        
        llOwnerSay((string)euler);
       
    }
    
}

However, the llOwnerSay((string)euler); returns <-90.00001, 0.00003, -150.00000> regardless of where the drum stops, i think you mentioned that it does not actually rotate, only for the viewer, but that's gone over my head, is there no way i can get the new position data when it stops?

if i look at the properties for the prim, the X,Y and Z are changing each time... 

Thanks again

Suzie

Link to comment
Share on other sites

13 minutes ago, naughtyniece said:

However, the llOwnerSay((string)euler); returns <-90.00001, 0.00003, -150.00000> regardless of where the drum stops, i think you mentioned that it does not actually rotate, only for the viewer, but that's gone over my head, is there no way i can get the new position data when it stops?

No, there isn't. Or at least .... let me frame things a different way. llTargetOmega makes non-physical things appear to revolve, but the movement is interpreted entirely on each person's local graphics card.  As far as the LL servers are concerned, nothing is moving. (It's the same thing that happens when an animation -- a dance, maybe -- appears to make you move, but the servers show you as standing still in one spot.)  As a result, you can get the new position data at any time, but it is always going to be the same, because the "new position data" is whatever the servers tell you.

You have two options from this point.  Both work fine, but one may be more appropriate than the other for your application. One option is to make your object physical. If you do that, llTargetOmega is handled by the servers instead of each client.  The other option is to run a timer that uses llSetLocalPos (or the SLPPF equivalent) in small increments, rotating the object in the servers at the same speed that llTargetOmega is rotating it in clients. That's the way some popular smooth rotating door scripts work, for example.  If you use either option, the servers obviously know exactly what the object's current rotation is at all times (or at least in small time slices, in the second case).

Edited by Rolig Loon
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Thank you all for your help on this, after many hours of trying and frustration I have come to the conclusion that i can not achieve the desired outcome.

I have learnt a great deal though, and thank you all for your input.

The game is going to the ever growing scrap heap, but the knowledge expands

thanks

Suzie

 

Link to comment
Share on other sites

sorry to hear ya gave up :P

here is some code for doing it without Target Omega...

you can drop in a prim and watch it spin, and give it's rot etc...

the code in the touch start only returns 5 different rots/faces tho :(

( may need to rotate the prim so the correct faces face up? )

integer speed;
rotation rot_xyzq;
vector euler;
 
rotation rot;
float time = 5.0;
integer x = 1;
move()
{
    rot = llGetLocalRot();         
    float i;
    llResetTime();
    do
    {  llSetLinkPrimitiveParamsFast( LINK_THIS, [PRIM_ROT_LOCAL,llGetRot() * llEuler2Rot(<-12,0,0>*DEG_TO_RAD)]); 
       llSleep( 0.02);
    }
    while (llGetTime() <= time);
     rot_xyzq = llGetLocalRot();       
     euler = llRot2Euler(rot_xyzq);
     euler *= RAD_TO_DEG;
    llOwnerSay( "my MOVE function rot is: " + (string) llRound(euler.z) );
   
}

default
{
    state_entry()
    {   
    } 
    touch_start(integer total_number)
    {  speed = 36;       
       do 
       {   llSetLinkPrimitiveParamsFast( LINK_THIS, [PRIM_ROT_LOCAL,llGetRot() * llEuler2Rot(<-12,0,0>*DEG_TO_RAD)]); 
           llSleep( 0.02);
        }
       while (--speed > 0);      
        rot_xyzq = llGetLocalRot();       
        euler = llRot2Euler(rot_xyzq);
        euler *= RAD_TO_DEG;        
        llOwnerSay( "my rot is: " + (string) llRound(euler.z) );
        llSleep(0.5);
        move();
       
    }
    
}

 

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

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