Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

moving between vectors

Daimos Baarer
Registered User
Join date: 15 Jul 2008
Posts: 2
11-01-2009 06:07
Hello,

maybe a stupid question but i cant find the answer.
I want to move an object between a startvector and a targetvector e.g:

vector startpos = llGetLocalPos();
vector targetpos = "just the target position" ;

function move2target (vector target) {

}

i have no problems to move the object on the x OR y OR z axis but i have the problem to move the object at all axis at the same time.


Greetings, Daimos
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
11-01-2009 07:37
OK, right now that question leads to more questions! How to get there depends on where you want to go.

llSetPos and the PRIM_POSITION part of llSetPrimitivaParams/llSetLinkiPrimitiveParams can only move 10 meters at a time. You can use looping to get more distance, or something like the library warpPos function to get there faster. Other than that, the destination coordinates should just be the x/y/z of where you want to go. Well sort of...

If you are using llGetLocalPos, does that mean you are trying to move a child prim in a link set? If so, that limits your prim's movement to a range of somewhere between about 2 to 54 meters, depending on how much other stuff is linked in. You can play with the editor to see how far things will go before they get stuck in your link set, or you can use this page to figure out your limits: http://wiki.secondlife.com/wiki/Linkability_Rules

Another thing to remember with child prims is that movement is always relative to the root prim's position and rotation, only the root prim normally moves along the region's coordinates. (You can figure in the root prim's rotation and position to "fake" it in a child prim.)

I don't know if any of that answers your question, but I hope it's enough to start with, so that you can know what to ask about :o
Daimos Baarer
Registered User
Join date: 15 Jul 2008
Posts: 2
11-01-2009 08:19
Thank for the answer,

and now my question:

i have a litte poseball (not a linkset), this posball has a start position.
Now i will move the poseball to the targetposition.
The movement has to be slowly and not warp.

I hope now its a little bit clear my question.

Regards, Daimos
jeaniesing Trilling
Loves to animate & script
Join date: 21 Oct 2006
Posts: 61
11-01-2009 09:00
I would use a series of llSetPos commands.....




first subtract one vector from the other.... (vector startpos-vector endpos= vector distance)

take the answer and divide it by the number of steps you wish to take (that number will vary by how smoothly vs. quickly you want it to move) the answer to this question will be a vector (vector distance/integer steps = vector onestep)

add the answer to the second question 10 times if you chose ten steps (do a for loop where integer i < steps, and inside the for loop
llSetpos(startpos+onestep); )



you might find you have to do endpos-startpos rather than what i showed.... i forget why *blush*
_____________________
Pinastri/113/171/30
Pete Littlebird
Registered User
Join date: 30 Sep 2009
Posts: 44
11-01-2009 09:33
This is one way of achieving smoothish motion:

CODE
default
{
touch_start(integer total_number)
{
llSetStatus (STATUS_PHYSICS, TRUE);
llMoveToTarget (llGetPos () + <0.0, 0.0, 5.0>, 2.5);
llSetTimerEvent (2.5);
}
timer ()
{
llSetTimerEvent (0.0);
llSetStatus (STATUS_PHYSICS, FALSE);
}
}
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
11-01-2009 10:07
From: Pete Littlebird
This is one way of achieving smoothish motion:

CODE
default
{
touch_start(integer total_number)
{
llSetStatus (STATUS_PHYSICS, TRUE);
llMoveToTarget (llGetPos () + <0.0, 0.0, 5.0>, 2.5);
llSetTimerEvent (2.5);
}
timer ()
{
llSetTimerEvent (0.0);
llSetStatus (STATUS_PHYSICS, FALSE);
}
}

After the llSetStatus in timer(), you should make sure to do llStopMoveToTarget(). Targets seem to be prim properties and if you don't cancel them, they'll still be active the next time the prim goes physical.
_____________________
Sick of sims locking up every time somebody TPs in? Vote for SVC-3895!!!
- Go here: https://jira.secondlife.com/browse/SVC-3895
- If you see "if you were logged in.." on the left, click it and log in
- Click the "Vote for it" link on the left
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
11-01-2009 10:23
(none of the below is how to make it fancy, just the basics of working around the most common llSetPos limits and surprises.)

I am glad it is the root prim or a single prim you want to move this time, because it is easier to do (and to explain). Child prims (including avatars) will move along with the root, and you get to use sim coordinates directly.

The first way most people will try is to use plain old llSetPos. Like I mentioned before, that will only move you 10 meters and then get stuck, so that can cause trouble. In these examples we'll be moving 10 meters east and north, and 5 meters up, a total of 15.

CODE

// first example, move the prim the "simple" way.
// We will get stuck and not complete the move.
default {
touch_start(integer det) {
vector origPos = llGetPos();

vector howFar = <10.0, 10.0, 5.0>; // this would be a 15 meter move

llOwnerSay("we want to move " + (string) llVecMag(howFar) + " meters");

llSetPos(origPos + howFar); // try to do the move with plain llSetPos

// but plain old llSetPos can only do the 10 meters
llOwnerSay("we really moved " + (string) llVecDist(origPos, llGetPos()) + " meters");

// leave us in the new location for a few seconds, then put everything back.
llSleep(5.0);
llSetPos(origPos);
}
}



With a little llSetPos loop, we can work around the limitation.

CODE

// second example, move the prim with a loop to complete the distance.

// a simple llSetPos() loop to get us where we want to go.
BigSetPos(vector where) {
while(llVecDist(llGetPos(), where) > 10.0) {
llSetPos(where);
}
llSetPos(where);
}

default {
touch_start(integer det) {
vector origPos = llGetPos();

vector howFar = <10.0, 10.0, 5.0>; // this would be a 15 meter move

llOwnerSay("we want to move " + (string) llVecMag(howFar) + " meters");

BigSetPos(origPos + howFar); // try to do the move with plain llSetPos

// this number may not be exactly 15, floats are goofy like that.
llOwnerSay("we really moved " + (string) llVecDist(origPos, llGetPos()) + " meters");

// leave us in the new location for a few seconds, then put everything back.
llSleep(5.0);
BigSetPos(origPos);
}
}


Now, there is another problem. Do we always want to move north/east/up in relation to the world as above, or do we want to align movement with the prim? To make it happen in relation to the prim, we have to dip our toes, but only lightly, into rotation. Spin the prim off center in the editor, then try the above script, and see that the crookedness is ignored. The third version below will treat the top of the prim as "up" instead.

CODE

// third example, use llGetRot() on our destination so that movement is aligned
// with the prim instead of the world.

// a simple llSetPos() loop to get us where we want to go.
BigSetPos(vector where) {
while(llVecDist(llGetPos(), where) > 10.0) {
llSetPos(where);
}
llSetPos(where);
}

default {
touch_start(integer det) {
vector origPos = llGetPos();

// Factor in llGetRot() to allow for a "crooked" prim.
// This time we are only moving straight up by 15 meters, so it is easier
// to see what happens.
vector howFar = <0.0, 0.0, 15.0> * llGetRot(); // this would be a 15 meter move

llOwnerSay("we want to move " + (string) llVecMag(howFar) + " meters");

BigSetPos(origPos + howFar); // try to do the move with plain llSetPos

// but plain old llSetPos can only do the 10 meters
llOwnerSay("we really moved " + (string) llVecDist(origPos, llGetPos()) + " meters");

// leave us in the new location for a few seconds, then put everything back.
llSleep(5.0);
BigSetPos(origPos);
}
}