llMoveToTarget seems to fix the position of all copied objects
|
|
BrownEyedSusan Beaumont
Registered User
Join date: 19 Jul 2007
Posts: 9
|
07-31-2007 15:20
I'm trying to make a single-prim (cylinder) "spinner" that will hovver 0.5m above where it is rezzed and spin around the z-axis when touched. I've tried using llRotateTexture and llOffsetTexture, but the motion is very unrealistic because the script is suspended after each operation. The example provided by Linden Scripting Language Reference ( http://oz.slinked.net/history/lsl2_reference.htm) uses physics and the motion is much smoother, so I'm now trying to use physics. As far as I know, this means I must use llMoveToTarget to hold the cylinder where I want it, otherwise it just drops to the ground once it's made physical. So the relevant code is: vector pos; llSay(0, "Hello"); llSetStatus(STATUS_PHYSICS, FALSE); llSetRot(<0.0, 0.0, 0.0, 1.0>); pos = llGetPos(); pos.z += 0.5; llSetStatus(STATUS_PHYSICS, TRUE); llMoveToTarget(pos, 0.1);
The problem I'm having is this. If I "Take" the object into my inventory, then rez a new instance (I normally edit the name before I do this to avoid duplicate objects of the same name), the new instance moves to the elevated position of the original, regardless of where it itself was rezzed. I want it to elevate above the position it was rezzed to, not fly to the position where I created the original. This doesn't seem to happen if I use llSetPos(), but I think I need to use llMoveToTarget() as I mention above in order to use physics. I have the same problem if I paste the script directly from the aforementioned reference. The code for this is provided at the end of this post. I have tried putting on_rez(integer start_param) { // Restarts the script every time the object is rezzed llStopMoveToTarget(); llResetScript(); }
into every state, but this doesn't seem to make a difference. Any ideas, anyone, please? The code from the Linden Scripting Language Reference ( http://oz.slinked.net/history/lsl2_reference.htm): // global variable that isn’t exposed
vector gStartPosition;
// global functions that can be called from any state
make_physical_and_spin(vector torque)
{
// double the torque because we want to
vector double_torque = 2.0*torque;
llSetTorque(double_torque, FALSE);
}
// state sections
// default state – all scripts must have a default state
default
{
// when a state is transitioned to, the state_entry event is raised
state_entry()
{
// Make physical so it can move
llSetStatus(STATUS_PHYSICS, TRUE);
// get the base stating position
gStartPosition = llGetPos();
// Move to 2 meters above the start position
gStartPosition.z += 2.0;
llMoveToTarget(gStartPosition, 0.5);
// transition to spin state
state SpinState;
}
// when a state is transitioned out of, the state_exit event is raised
state_exit()
{
// set critical damping to keep us on our stating location, with time constant of 0.5 seconds
llMoveToTarget(gStartPosition, 0.5);
}
}
// SpinState is a user defined state
state SpinState
{
state_entry()
{
// say hello on channel 0
llSay(0, "Starting to spin");
// call global function
make_physical_and_spin(<0.1, 0.1, 0.0>);
}
}
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
07-31-2007 16:05
On a side note - look into llTargetOmega, that will make an object 'spin', but it's handled by the client, so it doesn't require the use of physics. The downside is that every viewer may not see the object in the same position, but that's usually not an issue.
|
|
BrownEyedSusan Beaumont
Registered User
Join date: 19 Jul 2007
Posts: 9
|
07-31-2007 16:13
From: Ziggy Puff On a side note - look into llTargetOmega, that will make an object 'spin', but it's handled by the client, so it doesn't require the use of physics. The downside is that every viewer may not see the object in the same position, but that's usually not an issue. Thanks. Definitely worth looking into. But I need to know the rotation that's a result of the omega for what I'm doing (simple harmonic motion) so I'll need functions that will give me the rotation from the client's point of view if I use this function without physics. Susan
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
07-31-2007 16:54
Are you making it spin back and forth? It looks like you call it with afixed torque value. My physics is embarrassingly rusty, so would that result in constant angular velocity, or increasing angular velocity?
llTargetOmega takes a rotation axis, and a 'rate'. Not sure what he rate is, maybe radians / sec. In your case, the axis is <0,0,1>, since you want it to turn on the Z axis. The rate... if you want a constant spin rate, you could eyeball it.
To prevent the object from moving back to its original spot, try turning off physics as the first call in on_rez of whatever state it's in, and then see if you can make it move somewhere else. I'm not an expert on the physics engine, so someone else might have a better suggestion.
|
|
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
|
07-31-2007 21:47
setting the pos = to llGetPos and llMoveToTarget() in the on_rez event should fix any problem...
That way, the object is set to move to the location it is rezzed from rather than a location stored in its memory.
_____________________
--AeonVox--Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
|
|
BrownEyedSusan Beaumont
Registered User
Join date: 19 Jul 2007
Posts: 9
|
08-01-2007 00:58
From: Kenn Nilsson setting the pos = to llGetPos and llMoveToTarget() in the on_rez event should fix any problem...
That way, the object is set to move to the location it is rezzed from rather than a location stored in its memory. I'd have thought so, but... This is effectively what my scripts have been trying to do - llGetPos()..llMoveToTarget() are in default:  tate_entry() and on_rez resets the script. But it's as if llGetPos() gets a stored position rather that the position rezzed to, or so it seems. I tried putting on_rez(integer start_param) { vector pos; pos = llGetPos(); llMoveToTarget(pos, 0.1); llResetScript(); }
into every state, but the effect was as before.
But the problem seems to be solved (see next post)
|
|
BrownEyedSusan Beaumont
Registered User
Join date: 19 Jul 2007
Posts: 9
|
08-01-2007 01:07
From: Ziggy Puff To prevent the object from moving back to its original spot, try turning off physics as the first call in on_rez of whatever state it's in That did it. Actually, I had already been turning physics off indirectly before any calls to llGetPos() were made, and I thought calling llStopMoveToTarget() would be the call I needed. However, I tried you suggestion and have put: on_rez(integer start_param) { llSetStatus(STATUS_PHYSICS, FALSE); llResetScript(); }
in every state. I'm 90% sure that this has done the trick. (Since trying this, I rezzed one object which did the old trick of flying off to its predecessor's position, but I've now so many versions in my inventory it could have been one without this code in.) Thanks to everyone, Susan.
|
|
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
|
08-01-2007 02:11
Alternative texture animation. Does not require physics nor prim rotation. http://wiki.secondlife.com/wiki/LlSetTextureAnimHave a read through it.
|
|
BrownEyedSusan Beaumont
Registered User
Join date: 19 Jul 2007
Posts: 9
|
08-01-2007 07:05
Thank you. I've had a quick look and it definitely looks like something I wish I'd found earlier. Although I've now solved my physics problem I'll keep this in mind as an alternative to investigate. And it looks interesting for other projects. Thanks again. Susan.
|
|
Shadow Subagja
Registered User
Join date: 29 Apr 2007
Posts: 354
|
08-01-2007 10:19
Not sure if you are worried about collisions with avatars or external objects knocking your objects around in which cast the move to target is probably required, but if it is just the physics of falling that you are fighting you can use:
llSetBuoyancy(1);
To make your objects ignore gravity and float.
|
|
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
|
08-01-2007 12:11
on_rez(integer start_param) { vector pos; pos = llGetPos(); llMoveToTarget(pos, 0.1); llResetScript(); }
Maybe that was too slow? By the time the llGetPos has been called, the previously active llMoveToTarget has already moved the object to the old position, so llGetPos basically gets the old position? Just a guess. That might explain the behavior you saw.
|
|
BrownEyedSusan Beaumont
Registered User
Join date: 19 Jul 2007
Posts: 9
|
08-02-2007 02:17
From: Shadow Subagja Not sure if you are worried about collisions with avatars or external objects knocking your objects around in which cast the move to target is probably required, but if it is just the physics of falling that you are fighting you can use:
llSetBuoyancy(1);
To make your objects ignore gravity and float. I'm using physics to get a smoother animation than I was getting when I was setting positions on a timer without physics. Thanks for the tip. I didn't know about this function and I can see how it would remove the need for llMoveToTarget() which seems to be the cause of the grief I was having. If I have any more problems with llMoveToTarget() I'll try this. Susan. P.S. I have been sent flying by a few of my badly behaved objects. (Ouch)
|
|
BrownEyedSusan Beaumont
Registered User
Join date: 19 Jul 2007
Posts: 9
|
08-02-2007 02:24
From: Ziggy Puff on_rez(integer start_param) { vector pos; pos = llGetPos(); llMoveToTarget(pos, 0.1); llResetScript(); }
Maybe that was too slow? By the time the llGetPos has been called, the previously active llMoveToTarget has already moved the object to the old position, so llGetPos basically gets the old position? Just a guess. That might explain the behavior you saw.
That's my guess as well. I think the moral of the story is, if you use llMoveToTarget(), call llSetStatus(STATUS_PHYSICS, FALSE); as the very 1st thing you do in on_rez in every state. Susan.
|