# llMoveToTarget speed based on distance

Please take a moment to consider if this thread is worth bumping.

## Recommended Posts

Hey guys!

So this one's got me a little stumped, I don't know how to approach this to get the desired result.

I'm making some "drones" that will wander, but also follow and move between a predefined set of positions within a sim. I've opted for llMoveToTarget for this, but face an inconsistency, if you will.

I somehow need to calculate the damping value for llMoveToTarget based on the distance between vector points, so that the movement speed of the drone seems "realistic". By this I mean, for a short distance the drone should move slower between the points, but for a longer distance it should speed up to make the wait less, but without snapping to the target point.

I've already toyed with the idea of using llVecDist for this, but don't quite get how I can use it for my issue. Any input would be fantastic!

##### Share on other sites

The "damping value" is your time to target.  If you do absolutely nothing to the value -- just keep it constant -- then faraway objects will automatically move faster to get to the target than nearby objects do. After all, they have to cover a greater distance in the same time as the nearby ones are moving only a few meters.  That sounds already like what you want to do.  You can goose up the speed a bit (or slow it down), by calculating a fudge factor that is a linear function of distance.  For example, you could write

float Fudge = 1.0 / ( llVecDist(llGetPos(),TargetPos) );

so that you have llMoveToTarget(target, base_time * Fudge);

The farther away your drone is when it starts moving, the smaller Fudge is, so the less time it takes to reach the target.  You can make Fudge a more complicated function to get whatever behavior you want.  Just remember to use llTarget to define the distance at which the drone has reached the target.  Otherwise it will always creep up very slowly in the last meter or so.

##### Share on other sites
6 hours ago, Titty Luv said:

By this I mean, for a short distance the drone should move slower between the points, but for a longer distance it should speed up to make the wait less, but without snapping to the target point.

I can see where Rolig is going with her answer, but I think I must have interpreted this differently. Are you wanting it to move at a slow speed at first for say 5 or 10% of the trip, then move quickly for the next 80% of the trip, then move slowly again as it approaches its target in the last 10%?

##### Share on other sites
10 hours ago, Ruthven Willenov said:

I can see where Rolig is going with her answer, but I think I must have interpreted this differently. Are you wanting it to move at a slow speed at first for say 5 or 10% of the trip, then move quickly for the next 80% of the trip, then move slowly again as it approaches its target in the last 10%?

Hey Ruthven,

Yes, this is more what I had in mind. Apologies for not making it as clear as I'd liked Rolig. (your solution works well, but it's not quite what I was going for. I have no doubt that I'll find a use for it in the future so thank you!)

I understand that this solution is pretty complicated as it requires calculating the time to target and then altering the damping mid-movement. I don't expect anyone to go out of their way to write a solution, but any pointers would be fantastic.

##### Share on other sites

@Titty LuvPlease can you be more specific about how you want the object to behave?    You've told us that Rolig's solution isn't quite what you were going for -- how does the object's  desired behaviour differ from the way Rolig's suggestion has it working?

##### Share on other sites
4 hours ago, Titty Luv said:

it requires calculating the time to target and then altering the damping mid-movement.

If that's what you're after, it's not going to be easy.  llMoveToTarget assumes a constant speed. (Well, the function itself asks for a constant time of travel -- the "damping" variable -- anyway.  In practice, the moving object takes a brief time to start moving and then slows to a crawl at the end of travel because it's doing some averaging at both ends of the trajectory, but the speed at all other times is constant.)  There's no way that you can change the "damping" variable in flight.  Your only hope, if you want to use llMoveToTarget, is to break up the flight into segments and treat each one separately.  Unfortunately, piecing the segments together smoothly is probably impossible, given the averaging at the ends of each segment.

You may want to try using llSetKeyframedMotion, which does let you knit path segments together smoothly.  If the path is a straight line, assigning different times to each segment is straightforward.  Dealing with a curved path is more difficult, but still doable. I've given some thought to using Dora Gustafson's Bezier Toy as a starting point for problems like this but have never added a variable time function.  That would make a lovely drone.

EDIT:  Incidentally, if you're interested in seeing a KFM approach in action, visit the Lollercoaster in the Happy Hippo park in Bay City.  It speeds up as the car sails downhill and slows way down as it climbs, pretty realistically.

Edited by Rolig Loon
Example

##### Share on other sites
2 minutes ago, Rolig Loon said:

If that's what you're after, it's not going to be easy.  llMoveToTarget assumes a constant speed. (Well, the function itself asks for a constant time of travel -- the "damping" variable -- anyway.  In practice, the moving object takes a brief time to start moving and then slows to a crawl at the end of travel because it's doing some averaging at both ends of the trajectory, but the speed at all other times is constant.)  There's no way that you can change the "damping" variable in flight.  Your only hope, if you want to use llMoveToTarget, is to break up the flight into segments and treat each one separately.  Unfortunately, piecing the segments together smoothly is probably impossible, given the averaging at the ends of each segment.

You may want to try using llSetKeyframedMotion, which does let you knit path segments together smoothly.  If the path is a straight line, assigning different times to each segment is straightforward.  Dealing with a curved path is more difficult, but still doable. I've given some thought to using Dora Gustafson's Bezier Toy as a starting point for problems like this but have never added a variable time function.  That would make a lovely drone.

This is what I was thinking. And for the curved path, you would want to break it up into smaller segments, and add the short slower distances to the ends. I did something like this, but in reverse for a floating books path. Think Hogwarts Library books floating from shelf to shelf. Quickly moves out of the shelf, floats around slower to move in front of the next shelf, then quickly moves into place on the shelf

##### Share on other sites

Please take a moment to consider if this thread is worth bumping.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.