Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Target Omega called from another prim?

Cheewha Palen
Registered User
Join date: 27 Nov 2007
Posts: 78
07-30-2008 09:51
Hello,

I am working on an object that rotates when called from another prim. Its a wheel for a vehicle. If the vehicle isnt in motion then the wheels turning looks silly so justa roation script isn't enough. I want it to spin when forward and backward directional keys are called.

The example I am using is a texture alpha script modified with the "setalpha" line replaced with "targetOmega" lines. from the vehicle controls I am calling llSay( channel, "whatever";); to call out the command from the directional controls. its the same command announced in the toggle script from the alpha example.

in theory I thought this would work but the prim doesnt spin when called. To test this I set up the alpha toggle scripts with the target omega functions to see if it would work without being called from the vehicle script ( in other words I set up two linked prims one with the on/off script and one with the toggle switch script). It still does not spin.

So I am curious if I am not calling this correctly or if target omega perhaps doesnt work in this manner?

below are the modified setalpha scripts:

CODE

init()
{
llListen(1066, "", "", "");
llTargetOmega(<0,0,0>,PI,1.0);
}
SPIN()
{
llTargetOmega(<0,1,0>,PI,1.0);
}
NOSPIN()
{
llTargetOmega(<0,0,0>,PI,1.0);
}


default
{
state_entry()
{
init();
}
on_rez(integer start_param)
{
init();
}
attach(key attached)
{
init();
}
listen(integer chan, string name, key id, string msg)
{
if(llGetOwnerKey(id) == llGetOwner())
{
if(llToLower(msg) == "NOSPIN")
{
NOSPIN();
}
if(llToLower(msg) == "SPIN")
{
SPIN();
}
}
}
}


and the toggle switch

CODE



integer SPIN = 1;

default {
touch_start(integer n) {
if(SPIN)
llSay(1066, "SPIN");
else
llSay(1066, "NOSPIN");
SPIN = !SPIN;
}
}


Thanks for any advice you can offer.
Urrong Urnst
Registered User
Join date: 12 Jul 2008
Posts: 49
07-30-2008 10:31
That script wont help u much. U can get free car scripts in second life if u can find them and u can compare hov that works. An idea is that when main script senses that forward, backwars, left, right or any other key is pressed that it sends message to wheels with llLinkMessage the wheels then rotate/turn or whatever u want them to do. When keys are released it again sends the message to stop rotation.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
07-30-2008 12:52
Your problem is in these two lines:

if(llToLower(msg) == "NOSPIN";)
if(llToLower(msg) == "SPIN";)

llToLower converts the string to lower case. So the output of llToLower("sPiN";) is "spin", not "SPIN". Either replace those with llToUpper, or compare against "spin" and "nospin", i.e. the lowercase words.

If this wheel is going to be linked to the main vehicle, you should use link messages. I'm not sure if listens will work in a child prim for messages spoken by the root prim, and regardless, link messages are much more efficient for communicating within the same object.

I would echo Urrong's suggestion - pick up a free car and poke around the scripts to see how they did it.
Cheewha Palen
Registered User
Join date: 27 Nov 2007
Posts: 78
07-31-2008 06:14
Hi , sorry I did not get a chance to respond back yesterday. Thank you both for your advice. Ziggy was right about the llUpper() and llLower() being improperly cited that got the prim rotating. But oddly at best. At the same point in the vehicle script where fwd and back are defined I am calling the llSay (0, "SPIN/NOSPIN";) calls and while this works it has an odd side effect. I also call for an animation start/stop at this point in script which executes fine so the rotation quirk is strange to me. It is as if the longer i hold down say the fwd key the longer the prim will continue to spin after i have stopped.-- a quick tap fwd and the wheel spins for a second and stops accordingly. But if i take a say 2 minute ride the wheel will continue to spin after I stopped for about 2 minutes as if the effect is accumalative.

Anyhow I havent had a chance yet to go back and experiment with calling linked messages instead of llSay which will prolly do a better job. I have a free car script I am reviewing and it will take me a bit to work out as it makes some mostly mathmatical comments concerning whelel velocity and eulor rotations mostly for I believe the ability to turn left and right. I am only interested in the wheel spinning and not spinning so a matter of time to decipher it all. But that was good advice to check out the car scripts!

I will keep you guys posted and thanks again!