|
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
|
07-15-2009 13:10
I'm using two scripts in a build. One in the parent prim, one in a child. In the parent is a wander script. In the child is a "look at" script. I'll show you the two scripts. This is the wander.
float radius = 10.0; //distance from starting point to wonder float timeout = 7.0; //time between movement changes float max_dist = 7.0; //max distance to move on x/y axis per timeout
vector start; //starting location, found on start/rez
//randomly move somewhere within the defined circle random_move(){ vector pos; //new position float dist; //distance from center
//calculate the new position do{ //start with the current position pos = llGetPos(); //randomly update x/y cords pos.x += llFrand(max_dist * 2)-max_dist; pos.y += llFrand(max_dist * 2)-max_dist; //pos.z += llFrand(max_dist * 2)-max_dist; //calculate dist = sqrt( diff(x)^2 + diff(y)^2 ) //if we are outside of the circles radius try again }while( llVecDist( pos, start ) > radius);
// turn to new point llLookAt(pos,0.5,0.5); //move to the new point llMoveToTarget(pos,timeout); }
default{ state_entry(){ //get starting point and init timer start = llGetPos(); llSetTimerEvent(timeout); //move the object random_move(); } on_rez(integer i){ //get starting point and init timer start = llGetPos(); llSetTimerEvent(timeout); //move the object random_move(); } timer(){ //move the object random_move(); } }
And this is the look script.
//Causes Object to look at nearest Avatar. default { state_entry() { llSensorRepeat("", "", AGENT, 20.0, PI, 0.2); } sensor(integer total_number) { llLookAt( llDetectedPos(0) + < 0.0, 0.0, 1.0>, 1.0, 1.0 ); } }
The problem is, it seems like the look script in the child prim takes over the whole object, forcing the entire object to look at the nearest avatar. Which of course, completely breaks the rotation and direction on the first script. Any idea how to make these two scripts get along?
|
|
Ee Maculate
Owner of Fourmile Castle
Join date: 11 Jan 2007
Posts: 919
|
07-15-2009 13:28
I had a similar problem with a look at srcript in the same prim as a teleport script... all sorts of weird and wonderful things were happening! I got around it with a transparent prim surrounding the object for the teleport... but that won't work here. (Guess this is moral support that it's not a stupid question!  )
|
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
07-15-2009 13:30
i think the reason llLookAt from the child is effecting the whole object is cause it's physical. you might have you use set rot or something like that. i thought though, that those functions didn't work (correctly) on phys objects, maybe it's just the parent, cause then how would puppeteer and other prim anim scripts work on physical objects?
|
|
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
|
07-15-2009 20:14
Either way, I'm really confused
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-15-2009 21:29
without knowing how it's put together,and just assuming the root isnt supposed to rotate at all... I'd scrap the lookat in the second script and replace it with llSetLocalRot as Ruthven suggested, then (and i'm not sure this works for physical objects, but I believe so) use set status on the parent object and lock the x/y/z axis from rotating
_____________________
| | . "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
|
07-16-2009 11:45
Yeah, that's the thing. The root does rotate.
I'm trying to make a helicopter with a machine gun that will turn and target avatars. I'd just make the helicopter turn and do the targeting, but it doesn't stop moving when it does, so it looks silly.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
07-16-2009 20:23
should still be workable with llSetLocalRot in the child though you may want to cancel the root rotation to get real world relative rotation....
_____________________
| | . "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... | - 
|