Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rotating a thingy.

Rutager Thunders
Registered User
Join date: 10 Jun 2006
Posts: 3
10-19-2006 04:18
Hiya folks, I'm a newbie at scripting and I'm abuse company values using the pc to post onto a forum... ach well.

I want to make a prim rotate in 180 degrees in 2 steps.
So first step is rotate say to the left 90 degrees, stay in that position for a few seconds, then rotate to the left again in 90 degrees, stay there for a a few econds, then rotate to the right 90 degrees, stay there for a few seconds, then back to the original position, stay for a few seconds, then to the left...etc etc etc.

I've been ripping scripts apart trying to learn, on the wiki, getting headahces, pregnant gf telling me I should be spending more time doing...er.. other stuff. But all I want is this prim to shimmy!

Any help, kicks, punches, pokes in the eye, or a humane 'consumer' use of tranquilisers that won't harm an unbon child would be most appreciated!

Many thanks

Rutager
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
10-19-2006 04:38
Try looking up llSetRot in the wiki.
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
10-19-2006 04:49
The fun thing to remember about rotations is that if you multiply, it rotates one way, and if you divide it rotates the other way. Something to do with the math of it.

The script could look something like this:

CODE
float rotBy = 180.0; // Rotate 180degrees
integer steps = 2; // Number of steps to take
float wait = 1.0; // How long to wait before undoing the rotation
default {
state_entry() {
rotBy *= DEG_TO_RAD; // Convert rotBy to radians
}
touch_start(integer x) {
// Euler form is three values, rotation for some reason is four
// so need conversion. We rotate by the rotation we want, divided
// by the number of steps we intend to take
rotation rot = llEuler2Rot(<0.0, 0.0, rotBy> / steps);

integer i; // counter
for (i = 0; i < steps; ++i) { // Loop to do the 'forward' steps
llSetLocalRot(llGetLocalRot() * rot); // Rotate 'forward'
}
llSleep(wait); // wait for a bit
for (i = 0; i < steps; ++i) { // Loop to do the 'reverse' steps
llSetLocalRot(llGetLocalRot() / rot); // Rotate 'backward' around
}
}
}


This ought to do what you want and shouldn't be too complex to modify. Note that this will cope with any number of steps for any rotation.
You should note though that the llSetLocalRot() and llSetRot() commands both have a built-in delay of 0.2 seconds, so the transition won't be especially smooth. If you need a longer delay after rotating, simply put an llSleep() command into both of the loops to slow it down further.
_____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon
10gb DDR2 800mhz FB-DIMMS
4 x 750gb, 32mb cache hard-drives (RAID-0/striped)
NVidia GeForce 8800GT (512mb)
Rutager Thunders
Registered User
Join date: 10 Jun 2006
Posts: 3
Thanks
10-19-2006 05:05
Thanks very much for the script, I'll try it out when I get home. I'm sure it'll do what I need, although a smooth transition will be more ideal, I'm more than happy to accept what you've given and learn the rest myself.

I have been messing with the llTargetOmega scripts I have to get a smoother transition for what I want, but with disasterous results, I would post the code up but I'm currently at work, and I'm sure using forums breaches company internet usage, playing SL prolly won;t be a good idea.. hehe. Once again thanks :)
Haravikk Mistral
Registered User
Join date: 8 Oct 2005
Posts: 2,482
10-19-2006 07:56
From: Rutager Thunders
I have been messing with the llTargetOmega scripts I have to get a smoother transition for what I want, but with disasterous results, I would post the code up but I'm currently at work, and I'm sure using forums breaches company internet usage, playing SL prolly won;t be a good idea.. hehe. Once again thanks :)

Hmm, this may depend on what your intended use is? Can you give us more detail about it, for example, is it a swinging salloon door?
llTargetOmega isn't really intended for fixed rotation from one point to another, and it will very often look wrong as it's handled client-side and can be VERY hard to keep synchronised with how you want it to appear. It also sometimes doesn't switch off as expect (e.g you'll called llSetTargetOmega(ZERO_VECTOR, 0.0, 0.0); and it won't stop).
_____________________
Computer (Mac Pro):
2 x Quad Core 3.2ghz Xeon
10gb DDR2 800mhz FB-DIMMS
4 x 750gb, 32mb cache hard-drives (RAID-0/striped)
NVidia GeForce 8800GT (512mb)
Rutager Thunders
Registered User
Join date: 10 Jun 2006
Posts: 3
10-19-2006 08:36
Hiya, the script is going to be used on a swinging light kinda thing, a moving spotlight, from left to right. Like the 'movie spotlights' but for the front of my store. lol. Possibly disco/club lights on voice command too if and when I get the time to do it.

The llTargetOmega scripts I was using were what I initially thought made the rotation work. So was a good place, in my eyes, to start and learn about the different configurations, obviously none of it was working so I dived into the wiki (which is down for upgrades or something) and hundreds of posts before resorting to my own post.

I
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
10-19-2006 09:00
For a really, smooth swing like that you might be better looking at llRotLookAt and just maybe llLookAt. High damping will give you a slow swing and it should be smooth.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog