Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Naughty dog won't behave (llMoveToTarget)

Kirilisa Tigerpaw
Registered User
Join date: 6 Nov 2007
Posts: 15
01-17-2008 00:32
I have just made myself a dog (31 prims). He's cute.

Problem is, he's demented. I can't for the life of me make him come properly when called!

The script that manages his actions is inside his root prim which is a sphere (well not quite a sphere) located in his chest. The sphere is rotated so that when I do a llLookAt he is positioned upright (although he is kind of on a tilt instead of having 4 feet flat on the ground, which I guess happens because he is short and looking at my bellybutton, but that's another story). Sphere rotation is thus X: 0 Y:270 Z:180

What happens when I call him:
1) He stands up and looks at me
2) pauses for a moment
3) starts sliding over the ground toward me
4) when he's almost to his ending spot he does a full turn in place (while still moving)
5) he sits down as he finishes his moving/spinning

****What is interesting is, even if I comment out the second llLookAt (and sit) steps, he STILL does the fast turn in place towards the end of the movement, so that he is looking in approxomately the opposite direction! i.e. I don't think the spin has to do with the second llLookAt. Even more oddly, I suspect it may only happen when the avatar is standing certain places (i.e. the dog has to move a certain direction to get to the avatar.)

The entire effect of this is, he gets up, waits a moment, zooms over to me, spins in place and sits down. All very quickly. Bizarre dog!

Questions:
1) **Why** does he start spinning while moving? (He does it even when I comment out the second llLookAt and sit steps)
2) Why isn't he looking at my avatar when he's done with this whole thing? What's with looking the opposite direction from where he started?
3) Why isn't he pausing (sleeping for 1 sec) before sitting down?
4) What exactly does damping (in llMoveToTarget) mean anyway?
5) does llSetStatus(STATUS_ROTATE_X,TRUE) etc apply only to physical objects?
6) Is there a way to access just a certain part of a vector (e.g. just the x component)?

Here is the relevant part of the script that deals with coming when called.

CODE

// In the init() part of this script, I have set the below: Dog is not physical yet though.
// init() is called in on_rez, state_entry, etc.
//llSetStatus(STATUS_ROTATE_X,TRUE); // acts as Z axis due to root prim's rotation
//llSetStatus( STATUS_ROTATE_Z, FALSE);
//llSetStatus( STATUS_ROTATE_Y, FALSE);
.
.
.
if (message == "come") {
llOwnerSay("Coming!");
llSay(Chan, "stand"); // stand up

list avinfo = llGetObjectDetails(llGetOwner(), [OBJECT_POS, OBJECT_ROT]);
vector avpos = llList2Vector(avinfo,0);
rotation avrot = llList2Rot(avinfo,1);
vector offset =<-1,-1,-.5>; // just a guess as to where dog should stand
vector dogpos = avpos+offset;
llLookAt(dogpos, 0.1 , 0.2);
llSleep(.5);

llSetStatus(STATUS_PHYSICS, TRUE);
llMoveToTarget(dogpos, .5);
llSleep(1.0);
llSetStatus(STATUS_PHYSICS, FALSE);
llLookAt(avpos, 0.1 , 0.1);
llSay(Chan, "sit");
}



Any advice would be most welcome.

Thanks!
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
01-17-2008 01:49
I think it is the FIRST llLookAt() that is your problem. You're telling the dog to look at a point ('dogpos') and also move to that point. When it reaches the point, it's going to have a heck of a time looking at it. It won't know which way to turn. You may want to change where it should be looking before it gets too close. After a second with a damping of 0.5 seconds, it is going to be pretty close. I'm not sure why the final direction is opposite what you want though. Not from the amount I have looked at it thus far.

The damping of functions like llMoveToTarget() has to do with exponential decay. Think of it like that old philosopher's "paradox." If it takes you a second to halve the distance between your current position and your destination, and then another second to halve the distance again, how long will it take you to get there? Well, I don't think it takes the damping time to HALVE the distance; I think it gets closer than that (it would be interesting to run an experiment to find out how close). But it is a similar function.

If you have a vector variable named 'vec', the x-component of that vector is 'vec.x'. Similarly for y and z. Note that the expression before the '.<component>' MUST be a variable. It can't be a computed value or a literal vector ('<a, b, c>').
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-17-2008 03:07
testing has been done before that shows move to target can overshoot it's mark, perhaps it's fractionionally overshooting?

reference
_____________________
|
| . "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...
| -
Kirilisa Tigerpaw
Registered User
Join date: 6 Nov 2007
Posts: 15
01-17-2008 05:03
Oooooh so the llLookAt makes the thing *keep* looking at whatever direction is starts looking? I kind of thought it would make it just look at something and then it would stay pointing that direction by default. That's why I put in .5 second pause after a .2 second looking function- so he'd be finished looking by the time the moving started.

I didn't realize it was a continual/ongoing looking... if this is the case, how do I stop the looking from keeping going? I see no related stop looking functions in the SL wiki.

With regards to the overshooting the mark, I kind of thought he was undershooting, actually. It sure looks to me like he ends up a bit further than a metre away from the center of the avatar (if indeed one can eyeball distances in SL).

Thanks for getting back to me, both of you. I will keep playing around with it.
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
01-17-2008 06:00
From: Kirilisa Tigerpaw
I see no related stop looking functions in the SL wiki.
llStopLookAt() ?
Kirilisa Tigerpaw
Registered User
Join date: 6 Nov 2007
Posts: 15
01-17-2008 14:04
Haha, so right! I looked at the llLookAt page http://wiki.secondlife.com/wiki/LlLookAtand it only listed llRotLookAt as a related function so I figured there wasn't one. Should have looked at the long list :-o

Thanks! I will give it a shot and see if the dog starts behaving better...
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
01-17-2008 15:40
try messing with this script, i sometimes use it as a base when doing thing kind of stuff
Kirilisa Tigerpaw
Registered User
Join date: 6 Nov 2007
Posts: 15
01-17-2008 23:42
Augh, I am so at a loss. I throw myself upon your mercies. I may become dogocidal very soon.

(By the way, Mrc Homewood, I tried to look at your attachment but for some reason it dumped me the html source of the secondlife homepage instead of the txt file...)

I took out all the llLookAt stuff just to test, and the damn dog does mad twirls while he is moving to target! I must be missing something. Is it a function of his being physical? A function of which direction he is facing initially? Since I have not set any look target, is he just picking random stuff? I can't see a pattern. WHY is he spinning? I just don't understand.

When I call dog, he stands up, pauses, moves to me while spinning in a circle, pauses, sits down. Ends up facing in a completely unrelated direction to where he started at. I am so unbelievably frustrated by this. Is there any other way I can achieve this? How do other people's dogs come to them smoothly? I feel like it MUST be a function of his being physical. His mass, or something, if a virtual dog can have a mass.

I put the relevant (below) part of the script into a cube prim and tried it. No spinning. The I took 2 different sized cones and stuck them onto the cube to make it random and unbalanced. Tried again. NO SPINNING. So if it isn't a symmetry/mass thing, WHAT can be wrong with the dog?

CODE

if (message == "come") {
llOwnerSay("Coming!");
llSay(Chan, "stand"); //stand up

list avinfo = llGetObjectDetails(llGetOwner(), [OBJECT_POS, OBJECT_ROT]);
vector avpos = llList2Vector(avinfo,0);
rotation avrot = llList2Rot(avinfo,1);
vector offset =<-1,-1,-.5>; // for the follow/come part
vector dogpos = avpos+offset;
llSleep(.5);

llSetStatus(STATUS_PHYSICS, TRUE);
llMoveToTarget(dogpos, .5);
llSleep(1.0);
llSetStatus(STATUS_PHYSICS, FALSE);
llSleep(1.0);
llSay(Chan, "sit");

}


I hate my dog now. He's cute, but I hate him.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-17-2008 23:49
From: Kirilisa Tigerpaw
I didn't realize it was a continual/ongoing looking... if this is the case, how do I stop the looking from keeping going? I see no related stop looking functions in the SL wiki.

It was listed in the function footnote, but not entirely clear, so I tweaked the description and added llStopLookAt to the 'also' section.
_____________________
|
| . "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...
| -
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
01-17-2008 23:56
Yeah, it could very easily have to do with the object being physical. Who knows what the physics engine is deciding to do with friction and such, so long as that force you are applying to get it to the destination has its way.

I think if you want the dog to keep looking in a particular DIRECTION, rather than at a particular point, you might want to try llRotLookAt(), which takes a rotation, not a vector (so it can't possibly keep looking at a specified point). For comparison and a useful example, check out how llRotLookAt() is used in http://www.lslwiki.net/lslwiki/wakka.php?wakka=llLookAt