Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Making a pet follow you on the ground

Kala Bijoux
Material Squirrel
Join date: 16 Nov 2004
Posts: 112
08-28-2005 16:29
Hi,

Wondering if someone has good ideas for doing this. I'm trying to make a pet that'll follow me around on the ground even if I'm flying. Like any normal non-winged pet would :)

llMoveToTarget with my position makes it fly up to me. Setting hover height or buoyancy don't make any difference, I'm guessing the force applied by MoveToTarget is too strong. The Wiki does say that the force will persist until you stop moving to target or set tau to 0. Setting a strong downward force makes the object bounce around and looks pretty bad.

llMoveToTarget where the target is the ground under me (i.e. set target.z = llGround at my position) works OK if the ground is flat. But throw in a hill between me and the pet, and the pet tries to go through the hill (at least that's what I think is happening), and the pet gets stuck there.

My solution for now is to set incremental targets, and recalculate movement vectors each time, adjusting for ground. This way, if my incremental movement is small enough, it manages to navigate hills. I'm assuming that if the hill were sharp enough it wouldn't be able to climb it, but that's OK, a real pet wouldn't either. This actually works fairly well. The only thing I don't like is that it's pretty compute-heavy, with vector math and MoveToTarget calls being performed frequently.

Is there a better way to do this that I'm missing? Some combination of settings that would allow me to set one movement target and have the object navigate ground level changes on its own? What if I made it a vehicle and controlled the motors instead of setting movement/rotation targets - would that take care of this?

Thanks,
Kala
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
08-29-2005 04:26
Try what I'm doing in my own pets' scripts, maybe ? You can look into the code, grab a chocobo egg at either of my stores and take it apart. Basically, they use vehicle motor parameters to move towards the owner, like you suggested.

Or if this is too complicated (and my scripts tend to rely on obscure global variables for everything, so it's probably the case) for you try changing the target of llMoveToTarget, by changing the .z part of the vector into whatever the ground height is at this position.

Example:
CODE

sensor(integer c)
{
vector dest = llDetectedPos(0);
vector offset = dest - llGetPos();
integer steps = llCeil(llVecMag(offset) / 4.0);
integer n;
vector inctarget;
vector incoffset = offset / steps;
// using 4 meters between each incremental target, tweak to suit your needs

llRotLookAt(llAxes2Rot(offset, <0,0,1> % offset, <0,0,1>), llGetMass(), 0.2);

for(n=0; n<steps; ++n)
{
inctarget = llGetPos();

inctarget.z = 0.75 * (inctarget.z - llGround(ZERO_VECTOR)) + llGround(offset);
inctarget += incoffset;
// this sets the z value to the ground height at dest + the "hover height" of your pet
// minus one quarter of this "hover height" so that it does not start flying all the time

llMoveToTarget(inctarget, 0.3);
llSleep(0.275);
}
llStopMoveToTarget();
llStopLookAt();
}
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
08-29-2005 08:17
Thanks. That's kinda what I'm doing (posted the original question under my wife's login again). The one big problem I see with that is that the pet won't work indoors, or the top floor/roof of a building, or anywhere else where I'm standing on a surface that's above ground level.

If I make it a vehicle will it take care of that issue? Or does the vehicle's hover/buoyancy also only work relative to ground/water?
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
08-29-2005 09:19
Yes, using vehicle code will solve it instantly, almost hassle-free. Just reuse the code posted here, and replace the calls to llMoveToTarget with llSetVehicleVectorParam setting the engine to move forward instead.
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
08-29-2005 09:38
Thanks. I'll try that out.