Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Physics elevator?

Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
11-04-2009 17:48
http://pastebin.com/m2291060e

I'm trying to piece together a "realistic" physics enabled elevator with a script I've been playing with. The concept seems sound, but I'm running into two issues. A) Getting it to stop exactly where it should, and B) speed issues.

Anyone have any ideas?

CODE


float x = 0;
float y = 0;
float z = 0;
float target = 0;
float F1 = 5.0;
float F2 = 10.0;
float F3 = 15.0;
float Roof = 20.0;
integer thandle;

default
{
state_entry()
{
vector pos = llGetPos();
x = pos.x;
y = pos.y;
z = pos.z;
target = z;
state waiting;
}
}

state waiting
{
state_entry()
{
llListen(93724, "", "", "");
}

touch_start(integer total_number)
{
llDialog(llDetectedKey(0), "Choose floor", ["G", "F2", "F3", "Roof", "Cancel"], 93724);
}

listen(integer channel, string name, key id, string message)
{
if (message == "G")
{
target = F1;
state moving;
}
else if (message == "F2")
{
target = F2;
state moving;
}
else if (message == "F3")
{
target = F3;
state moving;
}
else if (message == "Roof")
{
target = Roof;
state moving;
}
}
}

state moving
{
state_entry()
{
llSetStatus(STATUS_PHYSICS | STATUS_BLOCK_GRAB, TRUE);
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
thandle = llTarget(< x, y, target>, 0.01);
llMoveToTarget(< x, y, target>, 0.4);
}

at_target(integer tnum, vector targetpos, vector ourpos)
{
llTargetRemove(thandle);
llSetStatus(STATUS_PHYSICS, FALSE);
llStopMoveToTarget();
state waiting;
}
}

_____________________
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
11-04-2009 18:25
For getting it to stop at the right spot, I usually just set the target about 0.15m away (YMMV) then llSetPos to the spot I want, once it gets close. You'll need to turn off physics first or it will ignore the llSetPos.

For speed, this usually takes a bunch of tweaking by me. The trick is to llTarget near where you actually want to be then do a llMoveToTarget to a point beyond that. How far beyond depends on how fast you want to be going when you hit the target...

edit: I think the 404 stuff can be avoided by making sure you have a space between < and letters..
_____________________
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
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
11-04-2009 18:32
From: Sindy Tsure
For getting it to stop at the right spot, I usually just set the target about 0.15m away (YMMV) then llSetPos to the spot I want, once it gets close. You'll need to turn off physics first or it will ignore the llSetPos.

For speed, this usually takes a bunch of tweaking by me. The trick is to llTarget near where you actually want to be then do a llMoveToTarget to a point beyond that. How far beyond depends on how fast you want to be going when you hit the target...

edit: I think the 404 stuff can be avoided by making sure you have a space between < and letters..


So you think I should add an llSetPos to the waiting state?

And the problem with that second option for the speed... it goes the same speed, no matter where I set the destination. Just floats up slowly.
_____________________
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
11-04-2009 18:41
From: Paul Wardark
So you think I should add an llSetPos to the waiting state?

You could do that. I'd probably put it in at_target since, in there, you know you're doing movement stuff and are pretty close to where you want to be. Either way will work, though.

From: Paul Wardark
And the problem with that second option for the speed... it goes the same speed, no matter where I set the destination. Just floats up slowly.

Try making the llMoveToTarget go twice as far as you want it to. Still do the llTarget on the spot you want it to stop at but tell the move to go 2x as fast.
_____________________
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
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
11-04-2009 18:45
From: Sindy Tsure
Try making the llMoveToTarget go twice as far as you want it to. Still do the llTarget on the spot you want it to stop at but tell the move to go 2x as fast.


That's just it. No matter WHAT I set the target to for the buttons, it just floats up slowly and never stops.
_____________________
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
11-04-2009 18:55
Hm.. Maybe it's a mass thing.. Dunno about that stuff much.

If you drop the script into just a simple cube, does it work as-expected? If so, somebody who deals more with vehicle-like stuff is probably who you need to talk to..
_____________________
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
Fillo Farber
Registered User
Join date: 6 Jun 2004
Posts: 60
11-04-2009 18:57
Are you aware that the speed (damping) is set in the float value?

llMoveToTarget( vector target, float tau );
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
11-04-2009 19:00
From: Fillo Farber
Are you aware that the speed (damping) is set in the float value?

llMoveToTarget( vector target, float tau );


The 0.4, yes? Yeah, set it to 10.0, no change.
_____________________
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
11-04-2009 19:03
From: Sindy Tsure
Hm.. Maybe it's a mass thing.. Dunno about that stuff much.

If you drop the script into just a simple cube, does it work as-expected? If so, somebody who deals more with vehicle-like stuff is probably who you need to talk to..


No, it doesn't even work right in a basic cube.
_____________________
Fillo Farber
Registered User
Join date: 6 Jun 2004
Posts: 60
11-04-2009 19:04
I can tell you this from experience - when you over shoot your target it should be by about 25% of the total distance. So if you elevator is going 4m you want to target at least 1m past that point. I don't remember for sure but I thought you had to decrease the float value to move faster. I may be wrong and you probably already tried that anyway.
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
11-04-2009 19:06
From: Fillo Farber
I can tell you this from experience - when you over shoot your target it should be by about 25% of the total distance. So if you elevator is going 4m you want to target at least 1m past that point. I don't remember for sure but I thought you had to decrease the float value to move faster. I may be wrong and you probably already tried that anyway.


Yeah, I'm getting the same results no matter what the float value. And now my cube is stopping almost immediately after it starts, not going very far at all, no matter which distance I set.

It's almost as if my states aren't kicking in the way they should...
_____________________
Fillo Farber
Registered User
Join date: 6 Jun 2004
Posts: 60
11-04-2009 19:14
Sounds like there may be something quirky in your script. I use this function in several items I have created and it can work like you expected.

*** edit ***
I got mixed up with another post for a moment and sent the wrong reply. heh - and I never made a mistake before today *sigh*
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
11-04-2009 19:15
From: Fillo Farber
Sounds like there may be something quirky in your script. I use this function in several items I have created and it can work like you expected.



That's what I'm guessing, too. But for the life of me, I don't see it.
_____________________
Fillo Farber
Registered User
Join date: 6 Jun 2004
Posts: 60
11-04-2009 19:27
Your targets aren't being added to the starting z

The script worked fine for me when I manually replaced "target" with 75. Being it started at 70m high.

Could this be the issue?
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
11-04-2009 19:41
From: Fillo Farber
Your targets aren't being added to the starting z

The script worked fine for me when I manually replaced "target" with 75. Being it started at 70m high.

Could this be the issue?

I spotted that before but assumed he was just working off of absolute heights. Now that you mention it, I'm thinking you're right, especially with water usually being at 20m..

Maybe...

thandle = llTarget(< x, y, z + target>, 0.1);
llMoveToTarget(< x, y, z + target + 5.0>, 0.4);

(though a little more math to make the movement consistant would be even better)
_____________________
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
Fillo Farber
Registered User
Join date: 6 Jun 2004
Posts: 60
11-04-2009 19:59
I think you will want to calculate your floor positions from the elevator's lowest point and do this early in the script so you can use them as constants. Set the elevator at the lowest floor and reset the script and begin from there. Otherwise, once the elevator goes up, the other floors are in a different position relative to the start Z position. It would be clumsy to calculate the target positions from each floor after the fact.
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
11-04-2009 20:46
From: Fillo Farber
I think you will want to calculate your floor positions from the elevator's lowest point and do this early in the script so you can use them as constants. Set the elevator at the lowest floor and reset the script and begin from there. Otherwise, once the elevator goes up, the other floors are in a different position relative to the start Z position. It would be clumsy to calculate the target positions from each floor after the fact.


There's my problem... I was hoping it could be relative to whatever position it's rezzed at without the extra math, using llGetPos...
_____________________
Fillo Farber
Registered User
Join date: 6 Jun 2004
Posts: 60
11-04-2009 22:33
Maybe I didn't explain that very well.

All you need to do is have for example:
F1 = pos.z; F2=pos.z+10; F3=pos.z+15; Roof = pos.z+20
assuming you reset the script while the elevator is on the "G" floor (aka F1)
You can put this right after the llGetPos. Then you make "target" equal the chosen floor value i.e. F1, F2, F3 or Roof as selected by the user in your dialog

Right now you have target = Z but you don't use that value anywhere. You assign one of the floor values to target without considering the Z that you started with.

The llMoveToTarget value is a coordinate, not a distance from your current position. Perhaps this is what is causing confusion for you.

It should be an easy fix.

*** Correction ***
F1 = pos.z; F2=pos.z+5; F3=pos.z+10; Roof = pos.z+15
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
11-05-2009 17:25
From: Fillo Farber
Maybe I didn't explain that very well.

All you need to do is have for example:
F1 = pos.z; F2=pos.z+10; F3=pos.z+15; Roof = pos.z+20
assuming you reset the script while the elevator is on the "G" floor (aka F1)
You can put this right after the llGetPos. Then you make "target" equal the chosen floor value i.e. F1, F2, F3 or Roof as selected by the user in your dialog

Right now you have target = Z but you don't use that value anywhere. You assign one of the floor values to target without considering the Z that you started with.

The llMoveToTarget value is a coordinate, not a distance from your current position. Perhaps this is what is causing confusion for you.

It should be an easy fix.

*** Correction ***
F1 = pos.z; F2=pos.z+5; F3=pos.z+10; Roof = pos.z+15


Ooh, I think that did it. Of course, now I'm going TOO fast, but this is good.
_____________________
Kaylan Draken
Registered User
Join date: 2 Dec 2006
Posts: 127
11-06-2009 00:16
a while ago i had that problem too.
How more ppl there are on the elevator how slower/bumpy the elevator gets.

I solved it with adding llBounency to it (1.1 for up and 0.9 for down)

and with move to target i used the event at_target to see if i am close to the end point
and then switch off physics and used llSetPos for get on endpoint
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
11-07-2009 11:46
Well, it was working. Now the at_target event isn't kicking in.
_____________________
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
11-07-2009 12:00
From: Paul Wardark
Well, it was working. Now the at_target event isn't kicking in.

Still using a 1cm target? Try making it 0.1m or 0.2m or so..

From: Paul Wardark
thandle = llTarget(< x, y, target>, 0.01);
_____________________
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
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-07-2009 12:41
From: Sindy Tsure
Still using a 1cm target? Try making it 0.1 or 0.2 or so..

thandle = llTarget(< x, y, target>, 0.01);


Hmmmm.. I can't find anywhere in the LSL documentation that defines the scale of the second variable in llTarget, but my bet is that it's meters, not centimeters. If so, your thandle has a range of 1 cm, not 0.1 cm. Not that it makes a difference what the units are if the numerical value works ....I'm just sayin' ...... :)
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Sindy Tsure
Will script for shoes
Join date: 18 Sep 2006
Posts: 4,103
11-07-2009 13:13
From: Rolig Loon
Hmmmm.. I can't find anywhere in the LSL documentation that defines the scale of the second variable in llTarget, but my bet is that it's meters, not centimeters. If so, your thandle has a range of 1 cm, not 0.1 cm. Not that it makes a difference what the units are if the numerical value works ....I'm just sayin' ...... :)

/me edits her post above to be more clear. I think you've hit on just about exactly what I was trying to say...
_____________________
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
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-07-2009 13:28
From: Sindy Tsure
/me edits her post above to be more clear. I think you've hit on just about exactly what I was trying to say...

Oh. Gotcha. ;)
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
1 2