|
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
|
06-11-2009 00:06
I'm making a little follower pet prim thing. And it's working fine. Except for one thing. Any time it hits an avatar or obstruction, it spins and rotates on all the axis' like mad. Makes it impossible to design any kind of top, bottom, front, or back... This is the script I'm using. Can anyone help me pinpoint exactly how to keep it from spinning wildly? vector offset = < -1, 0.5, 1.5>; //1 meter behind and 1 meter above owner's center.
default { state_entry() { llSetStatus(STATUS_PHYSICS, TRUE); // Little pause to allow server to make potentially large linked object physical. llSleep(0.1); // Look for owner within 20 metres in 360 degree arc every 1 seconds. llSensorRepeat("", NULL_KEY, AGENT, 20.0, PI,1.0);
} sensor(integer total_number) { // Owner detected... // Get position and rotation vector pos = llDetectedPos(0); rotation rot = llDetectedRot(0); // Offset back one metre in X and up one metre in Z based on world coordinates. // use whatever offset you want. vector worldOffset = offset; // Offset relative to owner needs a quaternion. vector avOffset = offset * rot;
pos += avOffset; // use the one you want, world or relative to AV.
llMoveToTarget(pos,0.4); } }
I understand that using "llLookAt" would probably do the trick, but I can't get it to work with this particular script.
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
06-11-2009 00:55
Your question was answered less than a week ago in this forum: /54/6e/324400/1.html
_____________________
From Studio Dora
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
06-11-2009 01:31
axis locking really is the best solution. but, if you can't lock the x and y axis as suggested in that thread (because you're allowing changes when going up a hill or some such), you can force the object back to near upright with a fun little function I've been playing with... rotation uConformPlane2Z( rotation vRotRaw, float vFltStrength ){ vector vVecFwd = <1.0, 0.0, 0.0> * vRotRaw; vector vVecTop = <0.0, 0.0, vFltStrength>; return llAxes2Rot( vVecFwd, vVecTop % vVecFwd, vVecTop); }
//--used in the following call llSetRot( uConformPlane2Z( llGetRot(), 1 ) );
this will incrementally rotate the object closer to being level... the higher the strength, the bigger the snap amount. you may want to use it in conjunction with llRotTarget, and call it from not_at_rot
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
|
llAxis2Rot(vector u, vector v, vector w)
06-11-2009 04:15
From: Void Singer rotation uConformPlane2Z( rotation vRotRaw, float vFltStrength ){ vector vVecFwd = <1.0, 0.0, 0.0> * vRotRaw; vector vVecTop = <0.0, 0.0, vFltStrength>; return llAxes2Rot( vVecFwd, vVecTop % vVecFwd, vVecTop); }
//--used in the following call llSetRot( uConformPlane2Z( llGetRot(), 1 ) );
I have one complaint: The 3 vectors in llAxis2Rot are not mutually orthogonal except in the special case where vRotRaw == ZERO_ROTATION and in a few other special cases; And vVecTop will only be a unit vector when vFltStrength == 1.0; I don't know how much this means in your case but I have experienced cases where it was crucial! "All three vectors must be mutually orthogonal unit vectors" Reference: http://wiki.secondlife.com/wiki/LlAxes2RotIf this sound familiar it is because I said it before: /54/c6/322162/1.htmlIn that thread I offered a solution too 
_____________________
From Studio Dora
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
06-11-2009 10:04
From: Dora Gustafson I have one complaint: The 3 vectors in llAxis2Rot are not mutually orthogonal except in the special case where vRotRaw == ZERO_ROTATION and in a few other special cases; And vVecTop will only be a unit vector when vFltStrength == 1.0; I don't know how much this means in your case but I have experienced cases where it was crucial! "All three vectors must be mutually orthogonal unit vectors" Reference: http://wiki.secondlife.com/wiki/LlAxes2RotIf this sound familiar it is because I said it before: /54/c6/322162/1.htmlIn that thread I offered a solution too  it should be (purposely) non orthogonal, for any rotation that can't be expressed as being solely around the z Axis... that's how it works... it averages that (based on the strength) to get a correction back towards the z-plane. I'm not up to writing a proof, or even a detailed process of the conformation, I can barely fight my way through quat math while making sense of it. but the action (and it's cause) are apparent enough... someone better at the math of it could probably clean it up to fewer steps, but i'm not there yet =) (and yes that's the thread it's from, but that formula wasn't actually a solution for the stated problem, instead it was an unexpected bonus for something else... like vulcanized rubber) interesting side notes: sqrt( 2 ) is the value at which it'll make a 50% correction from 90deg off the z plane (straight up or straight down). also in those 2 cases alone (straight up/down), is the x facing forced towards +X regional.
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
|
06-11-2009 17:26
I am learning so much, this is awesome. Thanks.
|