Keypress Only Works Right the Second+ Time
|
|
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
|
01-27-2009 15:33
okay, i couldnt think of a concise exact title. below is a nyterave sit script i have edited the heck out of. what i am trying to do, is have the user able to use pgup/pgdown to move their posterior up/down on the seat. the problem being that the prim they are sitting on may not be upright, so using the position +/- z coordinates was... wrong. however, i seem to have fixed that by applying the +/- z coordinates * the sit target's rotation. but it still is wrong. i have a sliced and sideways cube for a simple chair, so i am sitting on it sideways to be upright. the FIRST time i hit page up or page down, i am moved to the lower right quadrant of the chair. subsequent hits (or holds) of the key move me 'straight' up and down as intended. so the baffling question is.... WHY????????????????????????????????????????????? i set it to * the sit target rotation to start. its STILL screwy. WHY????????????????????
//--SitPos & SitRot -- position and rotation for the Sit Target //--replace these two lines with the output from your //--Tiny Sit Target Helper
vector SitPos = <0.15937, -0.45887, -0.39239>; rotation SitRot = <0.16508, -0.68758, 0.68755, -0.16509>;
// hovertext above ball. "" for none. // add '\n ' at the end to move text up i.e. // string HOVERTEXT="Sit Here\n "; string HOVERTEXT=""; // hovertext color; use regular vector vector HOVER_RGB= < 0.7, 0.7, 0.7>; float HOVER_TRANS = 0.70;
// Pie Menu Sit Text. Will only work for the // main prim but included it anyway. If no text // is entered between "" it won't be used. string SIT_TEXT="";
//--leave this as "" to use any (ONE) animation that you throw into the object, or to use NO animations (which is fine, too) string animation = "";
//--set to TRUE to have it explain how it works on sit //--set to FALSE for it not to talk integer VERBOSE = TRUE;
//--don't touch this one, it is used internally by the script vector currPos;
set_text() { if (llStringLength(HOVERTEXT)>0) { llSetText(HOVERTEXT,HOVER_RGB,HOVER_TRANS); } else llSetText("",<0,0,0>,0.0); }
default { state_entry() { llSitTarget(SitPos, SitRot); currPos = SitPos * SitRot;
if (llStringLength(SIT_TEXT)>0) llSetSitText(SIT_TEXT); set_text(); if(animation == "") animation = llGetInventoryName(INVENTORY_ANIMATION, 0); if(animation == "") animation = "sit_ground"; }
changed(integer change) { if (change & CHANGED_LINK) { if (llAvatarOnSitTarget() != NULL_KEY) { llRequestPermissions(llAvatarOnSitTarget(), PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS); } else { integer perm=llGetPermissions(); if (perm & PERMISSION_TRIGGER_ANIMATION) llStopAnimation(animation); currPos = SitPos * SitRot; set_text(); } } } run_time_permissions(integer perm) { if (perm & PERMISSION_TRIGGER_ANIMATION) {
llStopAnimation("sit"); llTakeControls(CONTROL_UP | CONTROL_DOWN, TRUE, FALSE); //--this pause here will let their AO apply their own sit, which we can then override. llSleep(0.3); if(animation != "sit_ground"); llStartAnimation(animation); llSetText("",<0,0,0>,0.0); if(VERBOSE) llWhisper(0, "Press Page Up and Page Down to adjust your sit height."); } } control(key id, integer level, integer edge) { if(level & CONTROL_UP) { currPos.z += 0.33; } else if (level & CONTROL_DOWN) { currPos.z -= 0.33; } llSetLinkPrimitiveParams(llGetNumberOfPrims(), [PRIM_POSITION, currPos * SitRot]); }
}
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-27-2009 21:40
Oh. What you want to keep in mind is that 'currPos' is in the root prim's coordinate system. So you don't want to add to the z component alone; you want to compute your offset from the current position based on the rotation. So you'll want to change: currPos.z += 0.33; llSetLinkPrimitiveParams(llGetNumberOfPrims(), [PRIM_POSITION, currPos * SitRot]);
to something more like: currPos += <0.0, 0.0, 0.33>*SitRot; llSetLinkPrimitiveParams(llGetNumberOfPrims(), [PRIM_POSITION, currPos]);
|
|
arton Rotaru
Registered User
Join date: 27 Aug 2007
Posts: 43
|
01-27-2009 22:05
Call llSetLinkPrimitiveParams immediatly after sitting in run_time_permissions event and adjust the SitPos accordingly.
|
|
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
|
01-29-2009 10:00
sorry guys;
hewee, your way gives me the same results i'm getting. i scoot off on a diagonal, then it goes straight up and down after.
arton, your way just shoves me diagonally off the seat to start. that's... not really helpful either :) it DOES, hoever, make the first keypress go straight instead of crooked.
i dunno guys. the caculations are correct, but the initial currPos must be wrong? i tried setting it equal to the SitPos (without the *SitRot), and that was wrong too. GAH!
_____________________
Why Johnny Can't Rotate: http://forums.secondlife.com/showthread.php?t=94705
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
01-29-2009 11:57
From: Bloodsong Termagant i dunno guys. the caculations are correct, but the initial currPos must be wrong? i tried setting it equal to the SitPos (without the *SitRot), and that was wrong too. GAH! Ahh. That makes sense if this is in a child prim. The sit target is in the child prim's local coordinate system. The position you want to set the avatar's position in is the root prim's coordinate system (the object's local coordinate system). So you'll want a local position of something like 'llGetLocalPos()+SIT_POS*llGetLocalRot()'. It may not EXACTLY fit still though, so you might want to set it immediately when the avatar sits down and consider it your "real" sit target.
|
|
arton Rotaru
Registered User
Join date: 27 Aug 2007
Posts: 43
|
01-29-2009 14:10
From: Bloodsong Termagant arton, your way just shoves me diagonally off the seat to start. that's... not really helpful either  it DOES, hoever, make the first keypress go straight instead of crooked. Yes, ofcourse. Thats why I wrote you have to adjust your SitPos accordingly. That means the initial SitPos.
|
|
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
|
02-06-2009 08:52
um...
for this test, its NOT in a child prim. sorry.
and if my sit target position is where i want the sitter's butt to be to start... what exactly am i adjusting it TO?
sorry guys, im not really understanding what you're trying to tell me.
i put in this, in the state entry: currPos =llGetLocalPos()+SitPos*llGetLocalRot();// SitPos * SitRot;
and when i hit page up, i start scooting sideways.
so i put in this... currPos =(llGetLocalPos()+SitPos*llGetLocalRot()) * SitRot;// SitPos * SitRot;
and i get back to where i was before. first keypress is diagonal. the rest go straight up and down.
arton, if the sitpos is the position of the sit target, and an avatar sits on the sit target, does that not make the avatars prim position in the link set = sitpos? if not, where does it make it, how do i find it/calculate it, etc?
_____________________
Why Johnny Can't Rotate: http://forums.secondlife.com/showthread.php?t=94705
|
|
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
|
02-06-2009 09:02
hewee...
looking over your post again, i'm not sure you've got that right, that im trying to move the avatar in the root prims coordinate system.
i want to move the avatar in the SIT TARGET's coordinate system.
this is what happens:
1: i have an object to sit on, made of one or more prims. one prim has a sit target in it.
2: i sit on a sit target helper ball, so that i am sitting upright in the chair, which is whatever relation to the prim with the sit target in it. i click the prim to get the sit target position and rotation, so that when i sit on it... i am sitting upright on the piece of furniture.
so the sit target always has me sitting upright, and the sit target's z is alwyas its up axis. now that may be pointing anywhichway compared to the prim it is IN. if the prim is upright, everything is fine. if the prim is upsidedown relative to the sit target, if its sideways, etc etc.
i still want to go 'up' and 'down' based on the sit target's local z axis.
now this worked fine, when i did it on a test prim, which, naturally was UNrotated. i sit. i press up, i go up; i press down, i go down. if i rotate the prim, with my initial no-rotation-compensation formula, i start scooting along the PRIM's local z axis, not the sit target's z-axis.
so now, if i re-orient the presumed position of the seated avatar by multiplying the sit position by the sit rotation... i get this weird thing where it banks off on diagonal the first keypress, then works right from there, afterwards.
maybe you said why, but like i say, i'm not understanding what you're trying to tell me.
|
|
arton Rotaru
Registered User
Join date: 27 Aug 2007
Posts: 43
|
02-06-2009 11:15
The avatar is the childprim. Where is the problem to adjust the initial sitting position, so that it match after you called LinkPrimitiveParams immediatly after sitting? Like Hewee said, make it so that the first LinkPrimitiveparams call is your "SitTarget". A "fake" SitTarget if you want to call it so. Try this: avatar sits on a simple box. //--SitPos & SitRot -- position and rotation for the Sit Target //--replace these two lines with the output from your //--Tiny Sit Target Helper vector SitPos = <-0.09370, -1.25000, 0.06000>;//adjusted this vector rotation SitRot = <0.16508, -0.68758, 0.68755, -0.16509>; // hovertext above ball. "" for none. // add '\n ' at the end to move text up i.e. // string HOVERTEXT="Sit Here\n "; string HOVERTEXT=""; // hovertext color; use regular vector vector HOVER_RGB= < 0.7, 0.7, 0.7>; float HOVER_TRANS = 0.70; // Pie Menu Sit Text. Will only work for the // main prim but included it anyway. If no text // is entered between "" it won't be used. string SIT_TEXT=""; //--leave this as "" to use any (ONE) animation that you throw into the object, or to use NO animations (which is fine, too) string animation = ""; //--set to TRUE to have it explain how it works on sit //--set to FALSE for it not to talk integer VERBOSE = TRUE; //--don't touch this one, it is used internally by the script vector currPos; set_text() { if (llStringLength(HOVERTEXT)>0) { llSetText(HOVERTEXT,HOVER_RGB,HOVER_TRANS); } else llSetText("",<0,0,0>,0.0); } default { state_entry() { llSitTarget(SitPos, SitRot); currPos = SitPos * SitRot; if (llStringLength(SIT_TEXT)>0) llSetSitText(SIT_TEXT); set_text(); if(animation == "") animation = llGetInventoryName(INVENTORY_ANIMATION, 0); if(animation == "") animation = "sit_ground"; } changed(integer change) { if (change & CHANGED_LINK) { if (llAvatarOnSitTarget() != NULL_KEY) { llRequestPermissions(llAvatarOnSitTarget(), PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS); } else { integer perm=llGetPermissions(); if (perm & PERMISSION_TRIGGER_ANIMATION) llStopAnimation(animation); currPos = SitPos * SitRot; set_text(); } } } run_time_permissions(integer perm) { if (perm & PERMISSION_TRIGGER_ANIMATION) { llSetLinkPrimitiveParams(llGetNumberOfPrims(), [PRIM_POSITION, currPos * SitRot]); llStopAnimation("sit"); llTakeControls(CONTROL_UP | CONTROL_DOWN, TRUE, FALSE); //--this pause here will let their AO apply their own sit, which we can then override. llSleep(0.3); if(animation != "sit_ground"); llStartAnimation(animation); llSetText("",<0,0,0>,0.0); if(VERBOSE) llWhisper(0, "Press Page Up and Page Down to adjust your sit height."); } } control(key id, integer level, integer edge) { if(level & CONTROL_UP) { currPos.z += 0.33; } else if (level & CONTROL_DOWN) { currPos.z -= 0.33; } llSetLinkPrimitiveParams(llGetNumberOfPrims(), [PRIM_POSITION, currPos * SitRot]); } }
|
|
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
|
02-12-2009 09:22
heyas;
okay, NOW i see what you mean. and yours works, although the sit target isnt where i wanted it. BUT....
i need to know how you adjusted it. because i have also recalled (and am trying to untangle) that lex had to do some adjustments for the sit target to come out right vs the avatar's actual position.
this is the math lex is doing. as per my usual M.O., i'm applying various types of math he's doing to my currPos in an effort to stumble on one that matches the sitpos :X
vector helper_pos = llDetectedPos(0); rotation helper_rot = llDetectedRot(0); vector my_pos = llGetPos(); rotation my_rot = llGetRot(); // calculate where the avatar actually is vector avatar_pos = helper_pos + <0,0,1> * helper_rot; // due to helper's sit target avatar_pos = avatar_pos - <0,0,0.186> + <0,0,0.4> * helper_rot; // correct for a bug in llSitTarget(), for helper sit target vector target_pos = (avatar_pos - my_pos) / my_rot; target_pos = target_pos + <0,0,0.186>/my_rot - <0,0,0.4>; // correct for the bug again, this time in my sit target rotation target_rot = helper_rot / my_rot;
i have to move it by .186 and .4 on some axes or other, somewhichway. i get that much :X
okay, through doodling and um... randomly multiplying and dividing by different rotations... i came up with this:
currPos = (SitPos - <0,0,0.186>/llGetLocalRot() + <0,0,0.4>)*SitRot;
which NEARLY works, except for the avatar being too far back and slightly to the right.
_____________________
Why Johnny Can't Rotate: http://forums.secondlife.com/showthread.php?t=94705
|
|
arton Rotaru
Registered User
Join date: 27 Aug 2007
Posts: 43
|
02-13-2009 00:10
I simply edited the SitPos vector by hand. Took me a minute or two.
Change in the edit window from 'world' to 'local'. Then you see the local x,y,z arrows of the prim. Now you can move the position left/right, forward/backward, up/down by editing the numbers of the SitPos vector <x= red arrow, y = green arrow, z = blue arrow> easily.
I would use the sit target helper to set up a default sittarget and adjust the rest by hand.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
02-13-2009 08:27
From: Bloodsong Termagant so the sit target always has me sitting upright, and the sit target's z is alwyas its up axis. now that may be pointing anywhichway compared to the prim it is IN. if the prim is upright, everything is fine. if the prim is upsidedown relative to the sit target, if its sideways, etc etc.
i still want to go 'up' and 'down' based on the sit target's local z axis. Ah. Okay. Well, it is still true that the sit target is relative to the (child) prim. And you want an offset relative to the sit target. So: vector childPrimPos = llGetLocalPos(); rotation childPrimRot = llGetLocalRot();
vector sitPosReal = childPrimPos+SIT_POS*childPrimRot; rotation sitRotReal = SIT_ROT*childPrimRot;
vector nudge = <0.0, 0.0, 0.2>*sitRotReal; // Or whatever avatar-relative offset vector newSitPos = sitPosReal+nudge;
|