Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Dynamic Pet Follow

Lylani Bellic
Evil Genius
Join date: 2 Jul 2008
Posts: 42
07-26-2008 20:03
Ok. I've been reluctant to post about this cause I know there is a lot of threads on the issue already but I've been looking through them finding more with each alternation to the search parameters and so far none of them have helped. Now it could be that I have already found exactly what I'm looking for help with and just didn't recognize it so please excuse any redundancy this post may be based upon :p

With that aside I am trying to make a pet, a flying one but that's besides the point, and I want it to; obviously, follow me. Problem is every time I look for anything on follow scripts, while working to make the pet follow, it always forces it to one position on one side of me. When I back up, it backs up too.

What I want instead is something that follows when I move but only tries to get within a certain distance of me and then stop, no matter what orientation to me it is. (eg not having to be exactly by my left arm) If I move to the left I want it to stay still until I leave a certain radius and then it will proceed to follow again. If I back up I want it to stand still until I pass its radius at the rear to then turn and follow that way.

I guess an easier explanation would be a sphere around the pet that, as long as I am inside it, anywhere inside, the pet is standing still but as soon as I leave the sphere it seeks to follow.

The way I have it working right now is a script embedded in the pet that uses llSensorRepeat to find the Holder (the object I then hold/wear) and tracks it. That's how it seemed such follow scripts worked.

Problem is, as I said, the only way I can get it to work is if it uses an offset and the pet hugs my arm, any alternative I've tried just won't work. Now I know I'm not the greatest at scripting, having only recently started learning, but from what I gathered from the Wiki and here this is what I wrote to make it follow me:

default
{
state_entry()
{
llSensorRepeat("Holder", "Holder", SCRIPTED, 40.0, 2*PI, 2.0);
}
sensor(integer total_number)
{
vector rad = llDetectedPos(0);
vector offset =<0.0,1.0,0.0>;
rad +=offset;
llMoveToTarget(rad, 1.0);
}
}


Is this at all possible or should I be satisfied that it likes to hug my left arm?
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
07-26-2008 21:15
I wouldn't be satisfied...

OK, let's assume the pet will follow its owner and let's get rid of the sensor.

Next, I see a flaw in your design. If the pet doesn't move when you're close enough, it also means that it won't move if you bump into it. You might want to consider it stepping back if you come too close.

Last, you didn't talk about the pet looking in any particular direction, so I'll just ignore the problem...

From: someone
Typonese script removed. See below.


Just my L$0.02 of the day... ;-)
Lylani Bellic
Evil Genius
Join date: 2 Jul 2008
Posts: 42
07-26-2008 22:15
Thanks for your input Kaluura.

First off, you lost me with a lot of that code. No wonder I couldn't get the thing to work as desired, that's a lot more complicated then I'd imagined.

I had also preferred, and probably should have mentioned, the use of the sensor and Handel device as I had thought it would be an interesting touch to allow others to 'walk to dog' persay and hold the Holder and the pet follow them without having to own the pet. But I defiantly am willing to drop that and stick with your code if that's not such a great idea. As I said I'm fairly new to this and appreciate the help tremendously and don't want to sound as if I'm not grateful for your efforts by not including the sensor.

That was the way I thought it had to be done and just figured the multiple (one at a time at least) targets to follow via whoever holds the Holder, was a good side effect of having to use the sensor.

I'll put this code to use to be sure, and hopefully have my little pet flying by my side (away from my left arm that is ;)).

Again, thank you for your help. I'll probably sit here for the next hour trying to figure out how the code does what it does :p

Edit:: I tried out your code, it doesn't work :s

I figured enough to comment out the last bit:
llMoveToTarget(target, 2.0); // Slower than the timer so the pet will just adapt.

but then a new line showed an error:
llRemoveTarget(Handle); // Stop moving...

(32, 21) : ERROR : Name not defined within scope

Seems it doesn't know what Handle is for and the code is confusing to me and I don't know what it's for either.
Destiny Niles
Registered User
Join date: 23 Aug 2006
Posts: 949
07-26-2008 22:49
Take a look at Scratch for Secondlife

http://web.mit.edu/~eric_r/Public/S4SL/
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
07-27-2008 20:14
If you spoke Typonese like me, you would have corrected the minor errors. Anyway, for the future generations of SL noo... new comers, here is a fresh working script copied and pasted from SL:

From: someone

float Minimum = 1.5;
float Maximum = 1.6;
vector Offset;
key Owner;
integer Handle;

default
{
on_rez(integer param) { llResetScript(); }

state_entry()
{
Owner = llGetOwner();
Offset = <0.0, Minimum, 0.5>;
Handle = llTarget(llGetPos(), 0.1);
llSetTimerEvent(0.25); // Yeah! Let's speed up!
}

timer()
{
list tempo = llGetObjectDetails(Owner, [OBJECT_POS, OBJECT_ROT]);
vector pos = llList2Vector(tempo, 0);
vector target;
if (pos == ZERO_VECTOR) // The pet lost you.
{
target = llGetPos() + Offset; // This will prevent it from moving.
}
else
{
target = pos + (Offset * llList2Rot(tempo, 1));
}
float distance = llVecDist(target, llGetPos());
llTargetRemove(Handle); // Stop moving...
if ( (distance < Minimum) || (distance > Maximum) ) // but restart when needed.
{
Handle = llTarget(target, 0.1);
llMoveToTarget(target, 0.3); //Slower than the timer so the pet will just adapt.
}
}
} // EOF


Just put that script in a physical ball and admire! ;-)