Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Object "position and physics" script problem

Ludvaig Lindman
Registered User
Join date: 2 Feb 2007
Posts: 78
07-12-2007 07:35
Hi, I've been trying to write a script. If i click on it, i want it to:

1) Record the current position of the object
2) Turn on physics of the Object it is in
3) Wait for several seconds
4) Put it back into the recorded position.

Here is the Code:

vector startPos;
vector curPos;
integer second;
vector position;

default
{
state_entry()
{
llSetStatus( 1, FALSE ); // turn off physics.
startPos = llGetPos();
}

touch_start(integer total_number)
{
startPos = llGetPos();
curPos = startPos;
llSetStatus(1,TRUE);
llSetTimerEvent(1);
second = 0;

}
timer() // do these instructions every time the timer event occurs.
{
second++;
curPos = llGetPos();
if ( second > 5 ) // then time to wrap this up.
{
// move object back to starting position...

{
llSetPos(startPos);


}

llSetTimerEvent( 0 ); // turn off timer events.
llResetScript(); // return object to ready state





}


}

}
-------
I think it must be a rather simple mistake, but I dont get it :-(

When I click on the object, it turns physics on, which makes it drop. That's just perfect. But it does not get back into the position it was in, before I clicked on it.

Thanks for helping.
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
07-12-2007 07:43
I don't see the problem.. Maybe try turning off physics before you reset the position and reset the script? Maybe try a small sleep of 0.5 or so, right before the script reset?
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- 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
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
07-12-2007 07:44
Not sure what else is going on here, but you probably want to turn physics off before trying to llSetPos back to the startPos; llSetPos won't work with physical objects (and if it did, it would just start falling again anyway).
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
07-12-2007 07:46
From: Qie Niangao
llSetPos won't work with physical objects

Oh! Right.. I knew that one, too..
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!!
- Go here: http://jira.secondlife.com/browse/SVC-1224
- 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
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
07-12-2007 09:44
From: Meade Paravane
Oh! Right.. I knew that one, too..


also as a side note, llSetPos() has a limit of 10m, so if you intend to use this script for obects that may move larger distances, it may be worth your while to look at using the library warppos() function instead.
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Ludvaig Lindman
Registered User
Join date: 2 Feb 2007
Posts: 78
07-12-2007 11:40
Yes, had to turn off physics first :-)

Thanks for helping