Jump to content

Continuous local rotation vs DEG_TO_RAD


Friday Siamendes
 Share

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

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

Recommended Posts

I am trying to attach a spotlight to an avatar, and rotate the spotlight along its local Z axis - so that the orientation of the spotlight can be adjusted and it will continue to rotate around the direction of its "beam."

I am an illiterate in scripting but have figured out that the script must Get Local Rotation, and I have tried several posted variants. The script below comes from an old post by the wonderful Rolig Loon - and it ALMOST does what I need. I have figured out how to set the desired axis, duration between touches etc. 

But I need continuous rotation (or as close as possible) - and the Euler syntax (if I understand it) rotates incrementally as it keeps re-reading the axes. I have tried replacing the Euler with other rotation phrases but I'm too dumb to succeed.

How can I program the object to behave exactly the same EXCEPT with "smooth" continous rotation rather than the tick-tick-tick-by-degree rotation? Thanks very much, wizards of script!

The script:

integer count;
default
{
touch_start(integer total)
{
llSetTimerEvent(1);
count = 0;
}

timer()
{
++count;
llSetRot(llEuler2Rot(<2.0,0,0> * DEG_TO_RAD)*llGetLocalRot());
if (count > 30) llSetTimerEvent(0);
}
}

Link to comment
Share on other sites

To avoid the jerky "stop start" look, lessen the amount of time between movement. This will achieve the affect of a more continuous, smooth movement to the prim. Here's your script modified as such below:

integer count;

default

{

touch_start(integer total)

{

llSetTimerEvent(0.25);

count = 0;

}

timer()

{

++count; llSetRot(llEuler2Rot(<2.0,0,0> * DEG_TO_RAD)*llGetLocalRot());

if (count > 30) llSetTimerEvent(0);

}

}

 

**NOTE: Your last written line here "if (count > 30) llSetTimerEvent(0);" will STOP the rotation after it's moved 30 times. I'm not sure why you'd do that as it's no where in your explanation of what you need you script to do. Remove this line from your script to make the movement continuous. Feel free to IM me directly in world if you have additional questions.

Link to comment
Share on other sites

You're never going to get smooth rotation with a script that moves incrementally.  The best you can do by making dozens of tinier steps is to makey the movement less jumpy.  For smooth rotation, you have two choices.  The best one in most cases is llTargetOmega.  It's nice and simple to script.  The other option, slightly harder to script but just as smooth, is llSetKeyframedMotion.  Take a look at both and decide.  You'll see sample scripts to play with in their wiki pages.

Link to comment
Share on other sites

I agree with 16, use llTargetOmega:)

// llTargetOmega attached by Dora Gustafson, Studio Dora 2012
// after the attach position is changed the script should be reset
vector rotAxis = < 0.0, 0.0, 1.0 >; // local prim axis to spin around
float speed = 1.25; // rad/S;
float gain = 1.0;
default
{
    state_entry()
    {
        llTargetOmega( rotAxis*llGetLocalRot(), speed, gain );
    }
    attach(key id)
    {
        if (id) llTargetOmega( rotAxis*llGetLocalRot(), speed, gain );
    }
}

This script will spin the prim about the prim's Z-axis when attached
It must be reset to update the spin after a changed attachment position and/or -rotation

Link to comment
Share on other sites

Thanks 16 but I have tried the TargetOmega scripts there and none of them work inworld as indicated. For example, the third script says:

//Rotates very slowly around a cylinder's local or global Z axis // .... Good for making a propeller that rotates regardless of initial orientation.

But whether attached to a root prim, attached to an avatar or unattached, the cylinder or cube follows the Global z axis (a sphere is not useful because it has no spotlight feature on a face). So I don't see how this would work for a propeller, for example, or my purposes. The first script on the TargetOmega page produced a syntax error, and the second script is for spheres so the axis syntax doesn't operate in a cute or cyclinder.

That's why I am trying to modify the script I quoted - it's the only one I've found that actually rotates around the internal/local axis when I tip it unattached or attach it to the avatar. Frustrating! Thanks for the suggestion though!

 

Link to comment
Share on other sites

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