Range of motion
|
|
Nectere Niven
Gadget Junky
Join date: 12 Jan 2007
Posts: 211
|
07-31-2007 14:20
How would I add limits to stop llLookAt from exceeding a natural range of motion?
i.e. eyes that follow a target (using a sensor to detect avatars) but dont roll all the way around and into the back of its head, or perhaps an objects head following a target but not spinning all the way around and limited to natural range of motion left/right/up/down. Hopefully that makes sense.
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
07-31-2007 14:47
Perhaps it would help to switch to llRotLookAt()  , where it might be easier to impose bounds on the rotation. The wiki  has a handy-dandy sample of computing the target rotation, given a target position.
|
|
Nectere Niven
Gadget Junky
Join date: 12 Jan 2007
Posts: 211
|
07-31-2007 14:55
I have been looking at that most of the day and dont understand how to say/write it since I cant find a working example of that.
I am not a scripter by any means, but when I see working examples of things I can fiddle with them and get them to work the way I want them to work, this is the last nail in the project I have been hammering together and I am stuck.
So how would I impose bounds on those rotations?
|
|
Nectere Niven
Gadget Junky
Join date: 12 Jan 2007
Posts: 211
|
07-31-2007 16:17
I tried using a rotlookat and it doesnt do anything for me
vector pos = llDetectedPos(0); llRotLookAt(llRotBetween(<1,-1,-1>,pos), 1.0, 1.0);
IN fact it stops any rotation at all and no longer tracks the avatar.
|
|
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
|
07-31-2007 16:25
If the object is stationary, just check to see if the point you want to look at falls within bounds for what's in "front".
If it's not stationary, you can do the same thing, just it's a bit harder to decdie what's in bounds as you have to take your rotation into account.
|
|
Nectere Niven
Gadget Junky
Join date: 12 Jan 2007
Posts: 211
|
07-31-2007 16:55
The object is stationary, but it should be allowed to be rotated if I want to rotate it. But if it has anything other than 0 rotation, the eyes dont point in the direction I want to, AND I cant seem to control under any circumstances with anything I have tried thus far to limit the range in which they follow the avatar.
I dont know what the proper syntax for llRotLookAt is I have tried everything under the sun I can think of and I come up short since I dont have a working example of it.
vector pos = llDetectedPos(0); llRotLookAt(pos + <0, 0, 1> , 1, 1); <--that makes an error
it asks for F32 strength and F32 damping which I thought should read as above which it doesnt, it does in the following case without error:
vector pos = llDetectedPos(0); llLookAt(pos + <0, 0, 1> , 1, 1); (although its still not achieving exactly what I want)
So I really have no idea what I am doing or where I am going wrong with this.
Also I am a newbie wanna be sorta script a few things or make use of scripts I see working to do what I want them to do, sometimes, other than that I havent a clue what I am doing.
|
|
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
|
07-31-2007 20:31
Apologies in advance if this is more confusing than helpful  , but here's a silly hack that kinda illustrates what I think is intended: a goofy eyeball that follows you around, within limits. vector AXIS_FWD = <1,0,0>; float RANGE = 20.0; float RATE = 0.5; float STRENGTH = 1.0;
float MAX_ROT_Z = PI_BY_TWO; float MIN_ROT_Z = -PI_BY_TWO; float MAX_ROT_X = 0.5; float MIN_ROT_X = -0.5; float MAX_ROT_Y = 0.5; float MIN_ROT_Y = -0.5;
float bound(float rawVal, float lowerBound, float upperBound) { float newVal = rawVal; if (rawVal < lowerBound) newVal = lowerBound; else if (rawVal > upperBound) newVal = upperBound; return (newVal); }
rotation imposeRotBounds(rotation rawRot) { vector rawEul = llRot2Euler(rawRot); vector boundEul = < bound(rawEul.x, MIN_ROT_X, MAX_ROT_X) , bound(rawEul.y, MIN_ROT_Y, MAX_ROT_Y) , bound(rawEul.z, MIN_ROT_Z, MAX_ROT_Z) >; return(llEuler2Rot(boundEul)); }
default { state_entry() { llStopLookAt(); // make cheezy eyeball: llSetPrimitiveParams( [ PRIM_TYPE, PRIM_TYPE_SPHERE, 0, <0.0, 1.0, 0.0>, 0.0, <0.0, 0.0, 0.0>, <0.20, 1.0, 0.0> , PRIM_COLOR, 1, <0, 0, 0>, 1.0 ]); llSensorRepeat("", llGetOwner(), AGENT, RANGE, PI, RATE); } on_rez(integer start_param) { llResetScript(); } sensor(integer num_detected) { rotation rawRot = llRotBetween(AXIS_FWD, llVecNorm(llDetectedPos(0)-llGetPos())); rotation boundRot = imposeRotBounds(rawRot); llRotLookAt ( boundRot , STRENGTH , RATE ); } }
|
|
Nectere Niven
Gadget Junky
Join date: 12 Jan 2007
Posts: 211
|
07-31-2007 22:22
Thank you, this actually works pretty good until I change the rotation of the root prim, since the eyes are attached to a head/body etc and its all linked together with a "brain" as root. I keep looking for a place to put in llGetLocalRot but cant seem to find one that works. "Lester" seems a bit doomed to always be either crosseyed or Linda Blair. vector AXIS_FWD = <0,1,0>; float RANGE = 15; float RATE = .1; float STRENGTH = .1;
float MAX_ROT_Z = 0.75; float MIN_ROT_Z = -0.75; float MAX_ROT_X = 0.75; float MIN_ROT_X = -0.75; float MAX_ROT_Y = 0.75; float MIN_ROT_Y = -0.75;
float bound(float rawVal, float lowerBound, float upperBound) { float newVal = rawVal; if (rawVal < lowerBound) newVal = lowerBound; else if (rawVal > upperBound) newVal = upperBound; return (newVal); }
rotation imposeRotBounds(rotation rawRot) { vector rawEul = llRot2Euler(rawRot); vector boundEul = < bound(rawEul.x, MIN_ROT_X, MAX_ROT_X) , bound(rawEul.y, MIN_ROT_Y, MAX_ROT_Y) , bound(rawEul.z, MIN_ROT_Z, MAX_ROT_Z) >; return(llEuler2Rot(boundEul)); }
default { state_entry() { llStopLookAt();
llSensorRepeat("", "", AGENT, RANGE, PI, RATE); } on_rez(integer start_param) { llResetScript(); } sensor(integer num_detected) { rotation rawRot = llRotBetween(AXIS_FWD, llVecNorm(llDetectedPos(0)-llGetPos() + <0,0,1.0>)); rotation boundRot = imposeRotBounds(rawRot); llRotLookAt ( boundRot, STRENGTH, RATE); } }
Btw this is simply a personal project, I make prim friends. I have a few of them 
|