Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Movement Script Going Wrong Direction?

Meligo Prevost
Registered User
Join date: 8 Mar 2006
Posts: 6
04-20-2006 01:24
I've been trying to get an elevator script working for some time now have have been plagued with problems that I just can't understand. I first worked with a physics based elevator that would apply a force to move the object that I was standing on through the air, but not only could I not get the forces to work out correctly, I couldn't figure out how to get my llSetPos to work at all. Because it was a physical object I was using llGetRegionCorner + llSetPos to set a possition that would be fixed. But for some reason, no matter which values I changed in the vector, the object would move every time I clicked it and it would never, repeat, never move up or down. I was confused because it was supposed to put the object in a fixed location based on fixed coordinates but it would move to a different possition each time.

Now I'm using a script that I found on the boards here where I'm having exacly the same problems. I cann get the object to move down the x and y coords but the elevator will not go up. I've swapped around the vector values in the movement portion of the script and it still will not move upwards. Here is the script with my modifications. Please help me here, I just don't. I've even tried to apply a llSetPos script to a box to try and get it to move to a location that is fixed in the Sim and it wont goto the right spot and wont go up....

Please help!

// SN_Elevator(adjustable speed version) was made by Seagel Neville as public domain, Dec 2005.

list heightList = [500]; // You have to put down the height of each floor here
list menuList = ["Home"]; // Dialog box's list. Go along with heightList.
integer speed = 20; // You can change the elevator speed here. 1 is the fastest.

key av;
float height;
integer CHANNEL;
integer HANDLE;
integer FloorSelection = FALSE;
vector StartPos;
vector AVsize;

StopSitAnim() // Don't sit on the floor. ;p
{
llStopAnimation("sit_generic";);
llStopAnimation("sit";);
llStartAnimation("impatient";); // Needed keyframes of legs.
} // If you want to know this more, make sure to replace this for "stand". ;p

ElevatorMove()
{
if(FloorSelection)
{
integer i;
for(i = 0; i <= speed; i++)
{
llSetPos(llGetPos() + (<0.0, 0.0, height / speed> * llGetRot()));
//llSetPos(llGetPos() + (<0.0, height / speed, 0.0> * llGetRot()));
//llSetPos(llGetPos() + (<height / speed * -1, 0.0, 0.0> * llGetRot()));
}
llUnSit(av);
llSleep(10);
while(llVecDist(llGetPos(), StartPos) != 0)
{
llSetPos(StartPos);
}
}
else
{
llUnSit(av);
llWhisper(0, "Plz touch this floor and select where you go first";);
}
}

default
{
state_entry()
{
llSetSitText("Get on";);
StartPos = llGetPos();
}
on_rez(integer start_param)
{
llResetScript();
}
changed(integer change)
{
if(change & CHANGED_LINK)
{
av = llAvatarOnSitTarget();
if(av != NULL_KEY)
{
llRequestPermissions(av, PERMISSION_TRIGGER_ANIMATION);
}
}
}
run_time_permissions(integer perm)
{
StopSitAnim();
ElevatorMove();
FloorSelection = FALSE;
}
touch_start(integer change)
{
key av = llDetectedKey(0);
AVsize = llGetAgentSize(av);
llSitTarget(<0, 0, (AVsize.z / 2)>, llEuler2Rot( <0, 270 * DEG_TO_RAD, 0> )); // Wow, don't you think this is a master touch? ;p
integer CHANNEL = llRound(llFrand(1000000) - 10000000);
HANDLE = llListen(CHANNEL, "", "", "";);
llDialog(av, "To what floor do you go?", menuList, CHANNEL);
}
listen(integer channel, string name, key id, string message)
{
height = llList2Float(heightList, llListFindList(menuList, [message]));
llListenRemove(HANDLE); // Is this a manner?
FloorSelection = TRUE;
}
}
Meligo Prevost
Registered User
Join date: 8 Mar 2006
Posts: 6
04-20-2006 01:27
The Movement function is where I was messing around with the script with the vectors. The first case moves along the x axis, the second moves along the y axis, and the third doesn't move at all. I just don't understand and I'm starting to get really frustrated.

You can see where I used comment marks to switch between the different lines for testing. None of them move UP ^ I just want it to move upwards...
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
04-20-2006 02:25
From: someone
CODE

integer i;
for(i = 0; i <= speed; i++)
{
llSetPos(llGetPos() + (<0.0, 0.0, height / speed> * llGetRot()));
//llSetPos(llGetPos() + (<0.0, height / speed, 0.0> * llGetRot()));
//llSetPos(llGetPos() + (<height / speed * -1, 0.0, 0.0> * llGetRot()));
}


In this for loop you don't seem to use the i value. My guess is you're looking for:
CODE
llSetPos(llGetPos() + (<0.0, 0.0, height * i / speed> * llGetRot()));


However, the height value here is more of an offset rather than an altitude. additionally, calling the above will result in the (height * i / speed) value increasing with each increment in i until it is larger than 10 at which point the llSetPos will not be able to complete the jump. a possible solution:

CODE

vector pos = llGetPos();
integer i;
for(i = 0; i <= speed; i++)
{
llSetPos(pos + (<0.0, 0.0, height * i / speed> * llGetRot()));
//llSetPos(pos + (<0.0, height * i / speed, 0.0> * llGetRot()));
//llSetPos(pos + (<height * i / speed * -1, 0.0, 0.0> * llGetRot()));
}


finally, you'll need to check the speed value to be sure that your jumps are within the 10m limit, otherwise your llSetPos calls are ignored, so something along the lines of:
CODE

if (height / speed < 10.0) speed = height / 10.0;


hope some of that is useful =D
Jigsaw Partridge
A man of parts
Join date: 3 Apr 2005
Posts: 69
04-20-2006 03:18
Is the elevator still set as a physical object? If so, llSetPos() will not have any effect, it only works for non-physical objects, unless you are just setting a child prim's position w.r.t the root prim.
Meligo Prevost
Registered User
Join date: 8 Mar 2006
Posts: 6
04-20-2006 19:02
No this elevator is not set as a physical object.
Meligo Prevost
Registered User
Join date: 8 Mar 2006
Posts: 6
SomeThing Wrong with the sim im in?
04-21-2006 01:24
I just put this script in an object and ran it...

vector Up = <0.0,0.0,1>;

default
{
touch_start(integer total_number)
{
llSetPos(Up);
}
}

It moves sideways... Sideways!?!? And then get this. I change the three values to
<1,0.0,0.0> and <0.0,1,0.0> and each one of these moves the object along the floor of the sim in the same direction. Do I have some settings messed up? Is the sim broken? Why doesn't a simple task like this work correctly?
Angela Salome
Registered User
Join date: 6 Oct 2005
Posts: 224
04-21-2006 01:58
From: Meligo Prevost
I just put this script in an object and ran it...

vector Up = <0.0,0.0,1>;

default
{
touch_start(integer total_number)
{
llSetPos(Up);
}
}

It moves sideways... Sideways!?!? And then get this. I change the three values to
<1,0.0,0.0> and <0.0,1,0.0> and each one of these moves the object along the floor of the sim in the same direction. Do I have some settings messed up? Is the sim broken? Why doesn't a simple task like this work correctly?


llSetPos sets the position of the object to the absolute position you give it. That position is the bottom left corner of the sim on the map, the southern and western corner. To put in a relative change use:
llSetPos (llGetPos () + Up);
:)