|
Dave Braess
Registered User
Join date: 6 Jun 2006
Posts: 33
|
09-11-2006 15:54
I am know for asking the impossible --but being new to scripting here goes--- I am building a dresser and want the drawers to open independant of each other. I have a door script and have build the drawer (faceplate and knobs seperately) when i link it to the unit it works fine until i add another drawer and then nothing works right !! any help would be appreciated
|
|
Llauren Mandelbrot
Twenty-Four Weeks Old.
Join date: 26 Apr 2006
Posts: 665
|
Dresser Drawers/Desk Drawers
09-11-2006 18:23
From: Dave Braess I am know for asking the impossible --but being new to scripting here goes--- I am building a dresser and want the drawers to open independant of each other. I`ve done this. I didn`t kow it was impossible, when I did it.  From: Dave Braess I have a door script and have build the drawer (faceplate and knobs seperately) when i link it to the unit it works fine until i add another drawer and then nothing works right !! any help would be appreciated Um, try not linking the drawers to the dresser?
|
|
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
|
09-11-2006 18:29
Each Drawer should have it's own touch script, that slides it out and back on touch. Nothing should be int he root prim if you want the doors to open individually (unless there is other functionality you want). Then you change the position of the drawer in relation to the root prim (taking into account the rotation and local axis). Use llSetPos, or llSetPrimitiveParams. For instance, if your root prim is not rotated and you want the drawers to slide along the x axis of the root prim (remember this is local) then you would do a llSetPos(llGetLocalPos() + <1, 0, 0>  . This will move the drawer 1 meter alonst the x from the root prim. ad for the face plate and handles, that is trickier, since there is no link heirarchy. so you would have to move all the prims at the same time. Hope that helps 
|
|
Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
|
09-11-2006 20:15
As mentioned, you have essentially two options: Either have each drawer (with knob, etc) a separate linked set, or use link messages to communicate touch. I recently did a set of scripts using link messages which works quite well.
Baron H.
|
|
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
|
09-11-2006 20:48
llSetPos(llGetLocalPos() + <1, 0, 0>  would work if the object is rotated appropriately. However, you can replace that <1, 0, 0> with a function that will work properly regardless of orientation. For instance, llSetPos(llGetLocalPos() + (llRot2Fwd(llGetRot()) * 0.5)); will position the drawer + 0.5m along the prim's local X-axis, not the world's x-axis. Multiply by -0.5 to go backwards. Similar 'rotation to direction' functions for the Y & Z axis are: llRot2Left(), Y-axis llRot2Up(), Z-axis Since the wiki is down... these functions, in a nutshell, take a rotation and convert is into a normalized vection pointing along the desired axis. For example, if the object is at ZERO_ROTATION, llRot2Fwd(llGetRot()) would return <1, 0, 0>.
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
09-12-2006 01:02
Didnt know it was impossible either  I used the linked message system, just one touch handler seemed more efficient to me. Each Drawer has the following script in it. // Sliding drawer script. // Originally based on JohnG Linden's Sliding Door Script modified by Cutter Rubio // Altered to work as a linked prim.
// displacement when open float fOffset =-0.5; // NOTE: if you want it to open right, you can either rotate it 180 degrees // around the Z axis or change this to <1.5, 0.0, 0.0> vector gRootPos = <0.0, 0.0, 0.0>; vector gActualPos = <0.0, 0.0, 0.0>; vector gOpenPos = <0.0, 0.0, 0.0>; vector gClosedPos = <0.0, 0.0, 0.0>;
integer iLinkNumber = -1;
GetPosition() { gRootPos = llGetRootPosition(); gActualPos = llGetPos(); // Linked Prims work in offsets from root. gClosedPos = gActualPos - gRootPos; gOpenPos = gClosedPos; gOpenPos.y += fOffset; iLinkNumber = llGetLinkNumber(); }
default { on_rez(integer arg) { llResetScript(); } state_entry() { // no physics until we need to open/close llSetStatus(STATUS_PHYSICS, FALSE); // but set proper values here anyway llSetBuoyancy(1.0); } link_message(integer sender, integer channel, string data, key id) { iLinkNumber = llGetLinkNumber(); if(channel == iLinkNumber) { GetPosition(); state open; } }
}
state closed { on_rez(integer arg) { llResetScript(); } state_entry() { llSetStatus(STATUS_PHYSICS, FALSE); // enforce proper location llSetPos(gClosedPos); }
link_message(integer sender, integer channel, string data, key id) { iLinkNumber = llGetLinkNumber(); if(channel == iLinkNumber) { GetPosition(); //state door_opening; state open; } }
}
state open { on_rez(integer arg) { llResetScript(); } state_entry() { llSetStatus(STATUS_PHYSICS, FALSE); llSetPos(gOpenPos); }
link_message(integer sender, integer channel, string data, key id) { iLinkNumber = llGetLinkNumber(); if(channel == iLinkNumber) { state closed; ; } }
}
The controller goes in the root prim : default { touch_start(integer total_number) { // llSay(0, "Touched."); integer i; for(i =0; i<= total_number;i++) { integer linknum = llDetectedLinkNumber(i); //Only respond to linked prim touches. if(linknum > 1) { string strText = (string)linknum; llMessageLinked(linknum, linknum, "", ""); //llOwnerSay("Sending Message to Prim " + strText); } } } }
|
|
Dave Braess
Registered User
Join date: 6 Jun 2006
Posts: 33
|
Thank You
09-12-2006 08:37
Thanks everyone for their help with this- guess its only impossible if you dont ask for help, once again all my thanks---- special shout out to ZenMondo Wormser who came by personnaly to help
|
|
EmeraldEver Cline
}(^o^){
Join date: 5 Jun 2005
Posts: 74
|
01-05-2007 15:28
From: DoteDote Edison For instance, llSetPos(llGetLocalPos() + (llRot2Fwd(llGetRot()) * 0.5)); will position the drawer + 0.5m along the prim's local X-axis, not the world's x-axis. Multiply by -0.5 to go backwards. Wonderful DoteDote, that was exactly what I was looking for ... 
|