Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Move toward a direction (non physics)

Anthalia Nemeth
Registered User
Join date: 8 Mar 2007
Posts: 17
09-04-2007 16:07
I'm been trying to make an object that will look for an avatar and then move toward that avatar. The object must remain nonphysical and if the avatar moves the object must continue to move toward the avatar.

I've tried llVecNorm with the avatar's position which kind of works but if the object gets to the avatar the object will then move away. And I tried llRotLookAt which I can't get working either.

Basically, all I need is for a non physical object to move toward a vector location.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
09-04-2007 16:52
They have a follower script in the library. Just tweak it around or strip the pieces you need to work with your non physical object.

/54/fc/29116/1.html
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Jotheph Nemeth
Registered User
Join date: 9 Aug 2007
Posts: 142
09-05-2007 20:52
From: Jesse Barnett
They have a follower script in the library. Just tweak it around or strip the pieces you need to work with your non physical object.

/54/fc/29116/1.html


The problem with that approach is that the op was asking for a non-phys approach, and llMoveToTarget only works on items flagged physical.

For non-phys prims, you have to use llSetPos, which has a limit of 10 meters per call.

Anthalia, does it matter if the object moves 10 meters at a time before it reaches the target user? If not, then you can call llSetPos(targetpos) in a loop until the target has been reached.

vector currentpos = llGetPos();
while (llVecDist(currentpos, targetpos) > .1) {
llSetPos(targetpos);
currentpos = llGetPos();
}

If you want it to stay near the user, you'll need to set a function to repeatedly check the position of the user and call the function to move to him or her.
Gordon Wendt
404 - User not found
Join date: 10 May 2006
Posts: 1,024
09-05-2007 21:21
From: Jotheph Nemeth
The problem with that approach is that the op was asking for a non-phys approach, and llMoveToTarget only works on items flagged physical.

For non-phys prims, you have to use llSetPos, which has a limit of 10 meters per call.

Anthalia, does it matter if the object moves 10 meters at a time before it reaches the target user? If not, then you can call llSetPos(targetpos) in a loop until the target has been reached.

vector currentpos = llGetPos();
while (llVecDist(currentpos, targetpos) > .1) {
llSetPos(targetpos);
currentpos = llGetPos();
}

and if you want the movement to be smooth I forget exactly how but there's a way to force a max distance on each move so you can just keep looping very short movements to get a (fairly) smooth glide. I think the way to do it would be to use a while statement to figure out it's position each time and base each subsequent (using a timer most likely to seperate the steps) move recalculate and move a small distance.
_____________________
Twitter: http://www.twitter.com/GWendt
Plurk: http://www.plurk.com/GordonWendt

GW Designs: XStreetSL

Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
09-06-2007 02:06
here's a basic bare-bones loop that might work (Can't test in world):


CODE

integer steps=10//number of steps to make for each movement
vector dir=target_pos - llGetPos();
integer i;
for(i=0; i <steps; i++)
{
llSetPos(llGetPos()+dir/steps);
}



this should take a position and move the object to it in 10 steps (2 seconds with the 0.2 second delay in llSetPos()). you could also calculate a fixed movement speed based on the distance away and have the number of steps taken adjust accordindly, as well as the amount moved within the llSetPos() call.
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
09-06-2007 09:04
From: Anthalia Nemeth
I'm been trying to make an object that will look for an avatar and then move toward that avatar. The object must remain nonphysical and if the avatar moves the object must continue to move toward the avatar.

I've tried llVecNorm with the avatar's position which kind of works but if the object gets to the avatar the object will then move away.


I'd do something like this:

vector my_pos = llGetPos();
vector target = (however you're getting the target position);
llSetPos( my_pos + llVecNorm(target - my_pos) );

Now loop this each time you get an update of the target position. This will move 1 meter in the direction of the target each time you loop.
_____________________
-Seifert Surface
2G!tGLf 2nLt9cG
Jotheph Nemeth
Registered User
Join date: 9 Aug 2007
Posts: 142
09-06-2007 14:34
This is why I asked if it matters if the non-phys prim moves 10 meters at a time.

There are problems with using partial movements such as calculating the direction and dividing it so it moves in smaller chunks. Basically, if you don't do it perfectly, you can overshoot the mark and have the prim keep going, or watch as it tries to go into the ground.

Even better, even if you have it working right, you'll have to calculate it right or the sucker will move way too slowly.

Yes, there are ways to do this but they are all a few levels of complexity higher than is probably necessary.
Anthalia Nemeth
Registered User
Join date: 8 Mar 2007
Posts: 17
09-07-2007 14:06
I solved the problem. I figured out how to rez an object facing a desired direction and then move toward that direction. I used llSetPos and a timer so even if the position is over 10m it will keep moving in that direction. Thanks everyone for the advice.

Btw, this is the code I came up with to rez the object facing a direction in case anyone needs it:

CODE

vector vDir = llGetPos() - vTarget;
vDir = -llVecNorm(vDir);

vTarget is the vector of the target object/avatar
and vDir is the direction that object is in relation to llGetPos