That means that before it moves to the next position along the path, it needs to check that that position is 40 meters above the ground. How do do I calculate what that vector position will be?
I suck at math and vectors.

These forums are CLOSED. Please visit the new forums HERE
Calculating the 'next position' in a path |
|
Harris Hare
Second Life Resident
Join date: 5 Nov 2004
Posts: 301
|
12-14-2005 08:16
I'm trying to write a while loop that will llSetPos() a prim along a path and have it check that the height stays at least 40 meters above ground along the way.
That means that before it moves to the next position along the path, it needs to check that that position is 40 meters above the ground. How do do I calculate what that vector position will be? I suck at math and vectors. ![]() |
Argent Stonecutter
Emergency Mustelid
![]() Join date: 20 Sep 2005
Posts: 20,263
|
12-14-2005 09:33
Call llGround() for the offset of that position, then use the result for the z.
|
Damien Took
Meat Popsicle
Join date: 3 Dec 2004
Posts: 151
|
12-14-2005 09:35
llGround is not accurate all the time.
You may have to add to the results of it. |
Harris Hare
Second Life Resident
Join date: 5 Nov 2004
Posts: 301
|
12-14-2005 09:45
What I can't figure out what the offset should be.
For example, if my prim is at <10,10,50> and the destination is <100,100,50>.... what is the offest position to scan that is 10 meters from where I am heading in the direction of the destination? There must be some formula for this. |
Tezkat Murakami
Ebil Genius
Join date: 25 Sep 2005
Posts: 12
|
12-14-2005 10:03
The offset is the vector you get after subtracting your current position from your destination, normalizing it, and then multiplying it by your step size.
Like so... CODE
|
Lit Noir
Arrant Knave
Join date: 3 Jan 2004
Posts: 260
|
12-14-2005 10:09
Hmm, perhaps llVecNorm to get the direction multiplied by 10 to not go over the max llSetPos move?
I think SetPos usually tries to get one axis aligned on it's first move, so for multiple moves it won't be a straight line, but I could be wrong about this. EDIT: Tezkat beat me to it, and with real code to, I'm a slacker. |
Tezkat Murakami
Ebil Genius
Join date: 25 Sep 2005
Posts: 12
|
12-14-2005 10:19
I think SetPos usually tries to get one axis aligned on it's first move, so for multiple moves it won't be a straight line, but I could be wrong about this. Hmm... I believe that llSetPos automatically moves to the "next" position 10m along a straight line between you and your target. So it actually does most of the work for you under ordinary circumstances, hence the simple one-line while loop that most people use. |
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
12-14-2005 11:15
I agree with Tezkat, if you give llSetPos() a distance more than 10m away it will move you 10m in that direction...
It becomes a bit trickier when you're trying to move a long distance AND stay a minimum height above the ground - you move 10m and if the height rises you move up, thus you move a shorter distance along the horizontal (xy) plane, but the height might be wrong and so on... imagine you were going over a narrowish ridge, you were ok where you were, you'd move a little up to the other side, but because of the height you don't go as far so the grounds higher... you're not high enough and so on. One option might be to calculate the positions (x, y) for a 10m move assuming you're not changing height. Check that height with llGround(). If you'll be too low, repeat for a 9m move and check if any height change requires a total travel of >10m (?19 ? 4.5m height change). If that's no good check for 8m moved (gives 6m vertical change) etc. You can STILL be stopped - if the height changes more than ?99 ?10m in one you'd be stuffed. You'd have to hop straight up 10m and repeat. I'm not sure if llVecMag() or using pythagorus is more efficient - you only need to work with the x and y components of the current and target positions and it might be better to do that as straight number crunching. |
Harris Hare
Second Life Resident
Join date: 5 Nov 2004
Posts: 301
|
12-14-2005 12:03
That helps a lot Tezcat. The rest of you have brought up some interesting logic questions I need to work out.
First, I should be more specific. I'm not trying to KEEP the object at 40m above ground. I'm just trying to keep it *AT LEAST* 40m above ground. Forty meters above ground is the minimum height that scripted objects can pass over any land that doesn't allow scripts. In fact, I'll probably end up making it 60 meters above ground just to be safe. At any rate, the goal is to allow the object to move towards its destination in as straight a path as possible as long as no land gets in the way. If it detects that the next position along its path has land high enough that the height + 60m is higher than the object's current altitude, the object should move up. Tezcat's script appears to do this. I'll have to test it. |
Tezkat Murakami
Ebil Genius
Join date: 25 Sep 2005
Posts: 12
|
12-14-2005 12:36
You can STILL be stopped - if the height changes more than ?99 ?10m in one you'd be stuffed. You'd have to hop straight up 10m and repeat. Well... llSetPos is non-physical movement, so it can't really be "stopped" by anything short of a no-script zone. If memory serves, moving into a cliff just boots you up to ground height. First, I should be more specific. I'm not trying to KEEP the object at 40m above ground. I'm just trying to keep it *AT LEAST* 40m above ground. Last I checked, the height limit for no-script zones was less than 20m above ground, actually. That still won't save you from the sheer cliff faces you see in some mountainous sims, however. If you need to be absolutely sure of never hitting a no-script zone, it might be safer to split up the movement into vertical and horizontal components. If you take a stairstep path instead of a straight line (always heading to a safe height before moving forward), you can guarantee that the distance will be maintained. |
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
12-14-2005 14:38
Well... llSetPos is non-physical movement, so it can't really be "stopped" by anything short of a no-script zone. If memory serves, moving into a cliff just boots you up to ground height. That's completely true. But in the context of this thread not relevant - we don't want something that rests on the ground (a default built into llSetPos()) we want it to stay at least 40m up, so we've got to consider what happens when the land height changes and how far we've moved and the worse case scenarios. |
Argent Stonecutter
Emergency Mustelid
![]() Join date: 20 Sep 2005
Posts: 20,263
|
12-14-2005 20:56
If you want to guarantee it's always at least 40m above the ground, then you can't just use llSetPos naively, you'll have to make the 10m steps yourself.
What you need to do is: 1. Move 40m up. (4 steps) 2. direction = llVecNorm(target-llGetPos()); delta = llGround(direction * 10) - llGround(<0,0,0> ![]() 3. if delta > 10 , llSetPos(<0,0,10> ![]() 4. if delta < (direction.z * 10) skip to 8 5. direction = llVecNorm(<direction.x, direction.y, delta/10> ![]() ![]() 6. if delta > 10, llSetPos(<0,0,delta-10> ![]() 7. go back to 4 8. llSetPos(direction * 10) 9. if not at target, go back to 2. |
Harris Hare
Second Life Resident
Join date: 5 Nov 2004
Posts: 301
|
12-15-2005 07:06
I tested Tezkat's script and without any modifications it worked perfectly! I even deliberately started the prim at the base of some sheer cliff walls and the prim had no trouble figuring out how to move up and over the cliff to the destination. It stayed 40m above the ground so it passed over no-script zones as well. Great stuff.
|