Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Clockwise Rotation

Milli Santos
La Princesse
Join date: 12 Oct 2006
Posts: 112
12-28-2006 02:33
Hi everyone! Scripting retarded here.

I have a script that rotates a prim anti-clockwise on the Z axis. Is there a way to make it rotate the other way, ie clockwise?

CODE
// Inter-object commands
string commandDerez = "derez";

// This is the channel the main vendor talks to rezzed models on
integer commChannel;

default {
state_entry() {
llTargetOmega(<0,0,1>,0.2,1.0);
}

on_rez(integer startParam) {
commChannel = startParam;
llListen(commChannel, "", NULL_KEY, commandDerez);
}

listen(integer channel, string name, key id, string message) {
llDie();
}
}


I have no clue what any of that means despite going to many scripting classes.:o

Also, while I'm here.. I'd like to make the object play music and have the rotation and music start and stop by touch. Can someone please tell me how to do that?

I would really appreciate any help. :)

Cheers! xxx
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
12-28-2006 02:51
From: Milli Santos

CODE
// Inter-object commands
string commandDerez = "derez";

// This is the channel the main vendor talks to rezzed models on
integer commChannel;

default {
state_entry() {
llTargetOmega(<0,0,1>,0.2,1.0);
}

on_rez(integer startParam) {
commChannel = startParam;
llListen(commChannel, "", NULL_KEY, commandDerez);
}

listen(integer channel, string name, key id, string message) {
llDie();
}
}



The key piece here is the llTargetOmega function. Looking this up in the LSLWiki ( http://lslwiki.com/lslwiki/wakka.php?wakka=lltargetomega ) gives us
CODE
llTargetOmega(vector axis, float spinrate, float gain)

what you need to do to rotate clockwise instead of anticlockwise is to negate the spinrate. therefore you are looking for
CODE

llTargetOmega(<0,0,1>, -0.2, 1.0);



From: Milli Santos

Also, while I'm here.. I'd like to make the object play music and have the rotation and music start and stop by touch. Can someone please tell me how to do that?


One possible way to do this is to use states and another would be to use an integer as a switch.

Firstly with a state switch you include the touch event in your code above and within the touch event you change state. In the second state, which I will call off_state, (though it would make more sense for the default to be the off state I thought that perhaps having the code resemble the original above as much as possible would help with understanding the changes made to the code) we have an llTargetOmega call with zero for spinrate (and will include a llStopSound too once we get around to that).
So here goes:
CODE

string commandDerez = "derez";

// This is the channel the main vendor talks to rezzed models on
integer commChannel;

default {
state_entry() {
llTargetOmega(<0,0,1>, -0.2, 1.0);
// llSound(string sound, float volume, integer queue, integer loop);
// or other suitable sound playing function
}

on_rez(integer startParam) {
commChannel = startParam;
llListen(commChannel, "", NULL_KEY, commandDerez);
}

listen(integer channel, string name, key id, string message) {
llDie();
}

touch_start(integer number_of_touches) {
state off_state; // switch states
}
}

state off_state {
state_entry() {
llTargetOmega(<0,0,0>, 0.0, 0.0);
llStopSound();
llListen(commChannel, "", NULL_KEY, commandDerez);
}

touch_start(integer number_of_touches) {
state default;
}

listen(integer channel, string name, key id, string message) {
llDie();
}
}


Now I also mentioned an integer switch, in this case you would initialise a global integer and when the touch event is triggered you change the integer from a 0 to 1 or 1 to 0, in LSL you can assign TRUE and FALSE in the place of 1 and 0, this makes it easier to read in most cases. With the variable changed we test it useing an if function, if variable is TRUE then we turn on otherwise (else) we turn off, and this would be represented by the following code:
CODE

integer spin_on = FALSE;

default
{
touch_start(integer total_number)
{
spin_on = !spin_on; // a clever way of changing a TRUE to FALSE or FALSE to TRUE, the ! operator known as NOT
if (spin_on == TRUE) // this line could be simplified to if (spin_on)
{
llTargetOmega(<0,0,1>, -0.2, 1.0);
// llSound(string sound, float volume, integer queue, integer loop);
}
else
{
llTargetOmega(<0,0,0>,0.0,0.0);
llStopSound();
}
}
}


for more information on sound functions see http://www.lslwiki.com/lslwiki/wakka.php?wakka=sound

Here ends the lesson of the day, hope it was helpful.
_____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum
Lightwave Valkyrie
Registered User
Join date: 30 Jan 2004
Posts: 666
12-28-2006 02:54
use negitive numbers in the spinrate like this :
CODE
llTargetOmega(<0,0,1>,-0.2,1.0);

use touch event to turn on/off i like states so this:
CODE
default
{
state_entry()
{
state on;//go to state on
}
}
state off
{

touch_start(integer total_number)
{
//llSay(14, "on"); //this is for debug
//turn things on here
state on;//go to state on
}
}
state on
{
touch_start(integer total_number)
{
//llSay(14, "off"); //this is for debug
//turn things off here
state off;//goto state off
}
}

then sound :
CODE
llPlaySound(string sound, float volume);
llStopSound();

-LW