The old rocking chair script. How to touch_start?
|
|
Paulo Dielli
Symfurny Furniture
Join date: 19 Jan 2007
Posts: 780
|
02-04-2007 19:09
FIRST PROBLEM SOLVED. PLEASE SEE POST #6 (BOTTOM) FOR EXTRA QUESTIONI managed to get the old rocking chair script moving smoothly, give and take e few prim building instructions it needs, but never mind. I know the movement lines are somewhat rigid (without timer), but it works for me. But what I don't seem to get managed is the touch_script command. That is: the movement must stop when someone left-clicks on the object and start again when they click again. Any suggestions? rotation Inverse(rotation r) { r.x = -r.x; r.y = -r.y; r.z = -r.z; return r; } rotation GetParentRot() { return Inverse(llGetLocalRot())*llGetRot(); } SetLocalRot(rotation x) { llSetRot(x*Inverse(GetParentRot())); }
vector normal = <1.55, 0, 0>;
default { state_entry() { @a; SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + 0.07>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + 0.14>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + 0.21>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + 0.14>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + 0.07>)); SetLocalRot(llEuler2Rot(normal)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - 0.07>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - 0.14>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - 0.21>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - 0.14>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - 0.07>)); SetLocalRot(llEuler2Rot(normal)); jump a; }
touch_start( integer num ) //Turn rocking off { state off; //Switch to the off state }
}
state off { state_entry() { @a; SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + 0.0>)); SetLocalRot(llEuler2Rot(normal)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - 0.0>)); SetLocalRot(llEuler2Rot(normal)); jump a; } touch_start( integer num ) //Turn rocking back on when touched { state default; } }
|
|
racush Cheeky
Registered User
Join date: 23 Jan 2006
Posts: 23
|
02-04-2007 20:48
Well here is what i can think of at the time not shure if its the best way to do this or not but its a simple way i could think to get what you like out of this. Script to controll rotations: rotation Inverse(rotation r) { r.x = -r.x; r.y = -r.y; r.z = -r.z; return r; } rotation GetParentRot() { return Inverse(llGetLocalRot())*llGetRot(); } SetLocalRot(rotation x) { llSetRot(x*Inverse(GetParentRot())); }
vector normal = <1.55, 0, 0>;
default { state_entry() { @a; SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + 0.07>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + 0.14>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + 0.21>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + 0.14>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z + 0.07>)); SetLocalRot(llEuler2Rot(normal)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - 0.07>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - 0.14>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - 0.21>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - 0.14>)); SetLocalRot(llEuler2Rot(<normal.x, normal.y, normal.z - 0.07>)); SetLocalRot(llEuler2Rot(normal)); jump a; }
}
Script to switch the rotation scipt on and off by touch: default { touch_start(integer total_number) { llSetScriptState("rocker",TRUE); state rocking; } } state rocking { touch_start(integer total_number) { llSetScriptState("rocker",FALSE); state default; } }
just slap both in together eather make shure the rotaiton script is eather named rocker or change the string to match in the touch controll script i hope this helps you out.
|
|
Paulo Dielli
Symfurny Furniture
Join date: 19 Jan 2007
Posts: 780
|
02-05-2007 02:06
Okay, thanks, this could work. But why doesn't touch_script work in the script mentionned above?
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
02-05-2007 02:17
From: Paulo Dielli Okay, thanks, this could work. But why doesn't touch_script work in the script mentionned above? You are falling foul of an LSL/SL limitation. No other event handler can run until the previous one has completed. Because of this the touch events will never get processed since the state_entry handler is never completing.
|
|
Paulo Dielli
Symfurny Furniture
Join date: 19 Jan 2007
Posts: 780
|
02-05-2007 08:31
From: racush Cheeky i hope this helps you out. Yes it does!! It works perfectly. Thanks for your help.
|
|
Paulo Dielli
Symfurny Furniture
Join date: 19 Jan 2007
Posts: 780
|
02-05-2007 16:18
EXTRA QUESTION...
DAMN!!! It's all designed, textured and working great. There is only one MAJOR PROBLEM: when I rez the complete linked chair and want to rotate it to place it nicely in a house for example, the entire chair jumps back to its original position. So the chair on rez can only be linear moved through the X and Y axis, but not rotate. That's a major bummer. How in heaven's name do I solve this problem?
For your information: first I linked the building objects. Then I linked the set to a poseball with animation script (poseball last). Then I linked the whole lot to the invisible prim (prim last). And finally I put the two above mentionned scripts in the invisible prim with 'edit linked parts'.
|
|
racush Cheeky
Registered User
Join date: 23 Jan 2006
Posts: 23
|
02-05-2007 18:38
ah sorry about that did not get much time to play with that setup but i see what you are talking about, I'll see if theres something that can be done to figure this out though one idea would to output the rotation data and posistion of the root in world and just imput that into the normal vector in the script. I'll see if there is a rig i can do so on command you can have the object output the numbers and then via another command set the vector so you will beable to aviod this problem, I shall post what i come up with shortly.
*edit* scratch the vector set by command since this script would need to be active to see that i'll play with it and see what i can do so hold tight.
|
|
Paulo Dielli
Symfurny Furniture
Join date: 19 Jan 2007
Posts: 780
|
02-06-2007 07:00
I'm anxiously waiting. Hope you can help me. Thanks in advance.
Edit: should it be done with llGetLocalPos or llGetPos, and where in the script?
|
|
racush Cheeky
Registered User
Join date: 23 Jan 2006
Posts: 23
|
02-08-2007 02:15
Well after atempting some different ways of rotation I was only really able to get something working but its alittle limited in one since, if you are to rotate the object say on its z you have to keep to eather a rotation of 0 or 90 or 180 and or there negative values since it seems not to like values between that as i was unable to get a way of rotating on a local since but i hope you can maybe figure a way to fix that i'm bit out of time to play with it much longer but this will give you some ability to adjust its rotation. I've updated the controller script to on command list its rotation values were it is in world so you may adjust the rocker script easyer but it still returies manual configureing mostly on x or z depending on how you rotated the object I was able to cut those into one float so you only have to adjust the 2 values at the top of the controller script. The values for y are hardcoded in and not shure if you will need to adjust them or not. Well i hope this will help or direct you in some way to what you are looking to do but here is the new scripts. rocker controll commands are as follow: /1 get vectors - will output current rotations of the prim this script is in.
default { state_entry() { llListen(1, "", llGetOwner(), ""); } listen(integer chan, string name, key id, string msg) { if (msg == "get vectors") { llSay(0, "Base rotation: " + (string)(llRot2Euler(llGetLocalRot())*RAD_TO_DEG) ); } } touch_start(integer total_number) { llSetScriptState("rocker1.4",TRUE); state rocking; } } state rocking { touch_start(integer total_number) { llSetScriptState("rocker1.4",FALSE); state default; } }
rocker float x = 0.0; float z = 0.0;
rotation LocalRot(rotation localrot) { rotation LocRot = localrot / ( (ZERO_ROTATION / llGetRot()) * llGetLocalRot()); return LocRot; }
vector center = <x, 0.0, z>; vector forward = <x, 5.0, z>; vector forward2 = <x, 10.0,z>; vector forward3= <x, 15.0, z>; vector forward4= <x, 20.0, z>; vector back= <x, -5.0, z>; vector back2= <x, -10.0, z>; vector back3= <x, -15.0, z>; vector back4= <x, -20.0, z>;
default { state_entry() { @a; llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(center * DEG_TO_RAD))]); llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(forward * DEG_TO_RAD))]); llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(forward2 * DEG_TO_RAD))]); llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(forward3 * DEG_TO_RAD))]); llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(forward4 * DEG_TO_RAD))]); llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(forward3 * DEG_TO_RAD))]); llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(forward2 * DEG_TO_RAD))]); llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(forward * DEG_TO_RAD))]); llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(center * DEG_TO_RAD))]); llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(back * DEG_TO_RAD))]); llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(back2 * DEG_TO_RAD))]); llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(back3 * DEG_TO_RAD))]); llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(back4 * DEG_TO_RAD))]); llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(back3 * DEG_TO_RAD))]); llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(back2 * DEG_TO_RAD))]); llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(back * DEG_TO_RAD))]); jump a; }
}
Well good luck to you I hope this will help you in your project if theres any questions feel free to ask. 
|
|
Paulo Dielli
Symfurny Furniture
Join date: 19 Jan 2007
Posts: 780
|
02-10-2007 21:30
Hey racush! I'm amazed and very grateful what you've done with the vector commands! I didn't reply earlier because I had a hard time using/understanding your adjustments and didn't want to bother you again with my stupidity. Since then I studied and practiced to understand now what's going on in the script. Thanks a million again!
Only thing is that the rotation adjustments indeed rotate the object, but not the swing in the script itself. So the swing rotation stays on a zero-degree x-y angle (even jumps back to its original position when rotating), which means that the rotated object swings in a weird way.
Is there any way that both swing (script) AND the object can be simultaneously rotated by myself or another user without the object/swing jumping back to its original position?
This is becoming a real challenge. Simply rotating a rocking chair at will shouldn't be so difficult. Why is this SO hard? It's really frustrating, though I warmly appreciate the help from racush and the others I got.
Any suggestions? PLEASE?
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
Newgy's version
02-11-2007 15:11
integer counter = 5; float angle = 0.07;
default { touch_start(integer total_number) { state running; }
moving_start() { llSetTimerEvent(0); } moving_end() { llResetScript(); } }
state running { state_entry() { llSetTimerEvent(0.2); }
touch_start(integer total_number) { llSetTimerEvent(0); state default; } timer() { --counter; if(counter == 0) { counter = 5; angle = - angle; } rotation rot = llGetRot(); rotation delta = llEuler2Rot(<0,angle,0>); rot = delta * rot; llSetRot(rot); } moving_start() { llSetTimerEvent(0); } moving_end() { llResetScript(); } }
|