Gaynor Gritzi
Registered User
Join date: 16 Aug 2006
Posts: 48
|
04-13-2007 11:11
I'm making a box with a lid so the lid opens when you click it to reveal the goodies within. I'm using this script (cobbled together from the forums as I really don't understand LSL rotations). This has a bug that if you turn the box through 90 degrees, the rotations go wrong. I'm sure it's something to do with local rotations, but baffled as to how to solve it. Any suggestions? default { touch_start(integer total_num) { rotation rot = llGetRot(); rotation delta = llEuler2Rot(<0,0,PI/2>); rot = delta * rot; llSetRot(rot); llSleep(0.25); rot = delta * rot; llSetRot(rot); state open; } }
state open { touch_start(integer total_num) { rotation rot = llGetRot(); rotation delta = llEuler2Rot(<0,0,-PI/2>); rot = delta * rot; llSetRot(rot); llSleep(0.25); rot = delta * rot; llSetRot(rot); state default; } }
|
ed44 Gupte
Explorer (Retired)
Join date: 7 Oct 2005
Posts: 638
|
04-13-2007 15:58
Let the object take care of tracking its rotation. default { touch_start(integer total_num) { rotation delta = llEuler2Rot(<0,0,PI/2>); llSetRot(llGetRot() * delta); llSleep(0.25); llSetRot(llGetRot() * delta); state open; } }
state open { touch_start(integer total_num) { rotation delta = llEuler2Rot(<0,0,-PI/2>); llSetRot(llGetRot() * delta); llSleep(0.25); llSetRot(llGetRot() * delta); state default; } }
|
Gaynor Gritzi
Registered User
Join date: 16 Aug 2006
Posts: 48
|
04-13-2007 16:22
No, that doesn't seem to solve it.
The box is the root prim and the lid is a child prim, and the box is on its side, like a cabinet.. When the box is turned at any angle, the lid rotation still goes wrong.
|
Fenrir Reitveld
Crazy? Don't mind if I do
Join date: 20 Apr 2005
Posts: 459
|
04-14-2007 00:57
If that lid script is to exist in a child prim of a link set, replace all llGetRot's with llGetLocalRot's. This will get the child prim's LOCAL rotation instead of its global -- which is what you want to be dealing with, so if the box is rotated, the lid opens the same way regardless of the root prim's rotation.
llSetRot's need to be modified, too, so it's llSetLocalRot(). However, for setting both the global position of the root prim and the local position of the child prim you use both llSetPos(). (Yes, makes no sense, but that's LSL for you.)
_____________________
---- ---- ----
|
Gaynor Gritzi
Registered User
Join date: 16 Aug 2006
Posts: 48
|
04-14-2007 03:42
Excellent. Thanks Fenrir, that's solved it. Here's the final script for anybody that needs it..... default { touch_start(integer total_num) { rotation delta = llEuler2Rot(<0,0,PI/2>); llSetLocalRot(llGetLocalRot() * delta); llSleep(0.25); llSetLocalRot(llGetLocalRot() * delta); state open; } }
state open { touch_start(integer total_num) { rotation delta = llEuler2Rot(<0,0,-PI/2>); llSetLocalRot(llGetLocalRot() * delta); llSleep(0.25); llSetLocalRot(llGetLocalRot() * delta); state default; } }
|
Justin Slade
Registered User
Join date: 6 Feb 2007
Posts: 132
|
adding on to your script
05-11-2007 13:38
This is nice script something similar to want I have been trying to write.
I'm trying to get the lid to open, then start another script and then when clicked to close, stop the other script.
Anyone heard of such an animal
Thanks
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
05-11-2007 14:09
From: Justin Slade This is nice script something similar to want I have been trying to write.
I'm trying to get the lid to open, then start another script and then when clicked to close, stop the other script.
Anyone heard of such an animal
Thanks You coudl either actually start aand stop the other script or just have it listen for linked messages?
_____________________
I'm back......
|
Justin Slade
Registered User
Join date: 6 Feb 2007
Posts: 132
|
thanks for the help
05-11-2007 16:20
Thank you for the help, Gaynor got it for me.. Many Thanks
|