Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Piston movement script.

Sham Omlet
Registered User
Join date: 26 Mar 2006
Posts: 9
08-17-2006 08:23
Hi there I am sorry to bother you all. I have a scripting problem, and am very new to scripting. The following (Fig 1) is a small diagram to help visualize the problem I am trying to solve.

I have three seperate linked objects, lets call them Main cylinder (That houses the two pistons) and Piston 1 & 2.

I simply want to script Piston 1 & 2 moving up and down in a piston-like manner, into the main cylinder, I would eventually like this to trigger whe movement controls where pressed, but I think I can figure that out myself. The animation of the pistons is confusing me. Do any of you have any hints, or starter example scripts to work from? How would you solve this problem?

Fig 1.
Sham Omlet
Registered User
Join date: 26 Mar 2006
Posts: 9
08-17-2006 11:56
So I put the following script into the piston, and it moves how I want it too when it is touched, however, there are problems (Below).

CODE

touch_start(integer total_number)
{

llSay(0, "Piston supposed to be moving..");
vector currentPosition;
currentPosition = llGetPos();
currentPosition.z = currentPosition.z + 1;
llSetPos( currentPosition );
currentPosition.z = currentPosition.z - 1;
llSetPos( currentPosition );

}



Problems:
1. The piston will not move when the entire assembly is linked together.
Is there a way to make the object move when it is linked to others?

2. There is no way to synch the up and down movements of the independant piston scripts.
Unless maybe messages to each other but that seems like a terrible idea?

Questions:

1. Would it be possible to keep the pistons in the cylinder and have them rez fully extended when in the correct position when the cylinder is rezed? If both pistons were controlled in one script it would mean I could synch them easily enough.

2. When the cylinder is worn on the spine, the above script doesnt work any more. Should I use an animation overrider or something to lock the default AV in one position? So that when you move around the map the cylinder does not move with the spine. Also, is there anyway to script this?

Hopefully somebody has the time to help me out.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-17-2006 12:50
While 'llGetPos()' always returns region coordinates, 'llSetPos()' uses object coordinates for child prims (and since you cannot move child prims outside a certain distance from the parent, it is silently failing, though occasionally you might see odd movement if you happen to be close to the region's origin). Your movment should work a lot better if you use 'llGetLocalPos()' in place of 'llGetPos()'.
Azurei Ash
The Sticky!
Join date: 12 Jan 2006
Posts: 38
08-17-2006 12:50
From: Sham Omlet

1. The piston will not move when the entire assembly is linked together.
Is there a way to make the object move when it is linked to others?

As soon as this becomes a child prim, things will work a little differently, namely llSetPos will be setting the position in relation to the root prim, so you'll want to look into using llGetLocalPos to get the local position relative to the root prim and go from there.

From: Sham Omlet

2. There is no way to synch the up and down movements of the independant piston scripts.
Unless maybe messages to each other but that seems like a terrible idea?

Yes, you'll need to use messages, but that's not a bad thing. Look into llMessageLinked for sending messages between linked prims.

From: Sham Omlet

1. Would it be possible to keep the pistons in the cylinder and have them rez fully extended when in the correct position when the cylinder is rezed? If both pistons were controlled in one script it would mean I could synch them easily enough.

I'm a bit confused by your wording here, but I think what you want is for them to rez in a correct position, in which case you can set their positions on rez, but I wouldn't think this is necessary.

From: Sham Omlet

2. When the cylinder is worn on the spine, the above script doesnt work any more. Should I use an animation overrider or something to lock the default AV in one position? So that when you move around the map the cylinder does not move with the spine. Also, is there anyway to script this?

I'm not sure I completely understand you, but I think your problem here again is from llGetPos, which in an attachment returns the position of the avatar wearing the attachment in region coordinates.

As far as overall strategy, I would recommend the following approach:

Have one controller script that sends link messages to each scripted piston when they should go up or down. This should be fairly straight forward, but ask again if you need help figuring things out.

From: Sham Omlet

Hopefully somebody has the time to help me out.

I'm not at work right now... really, I'm not.

~Az
Jopsy Pendragon
Perpetual Outsider
Join date: 15 Jan 2004
Posts: 1,906
08-17-2006 14:22
For something to be worn, you may want to try setting up an animated texture instead. Sure it'd be flat and perhaps not as visually appealing (not to mention the difficulty in setting up the custom texture).
_____________________
* The Particle Laboratory * - One of SecondLife's Oldest Learning Resources.
Free particle, control and targetting scripts. Numerous in-depth visual demonstrations, and multiple sandbox areas.
-
Stop by and try out Jopsy's new "Porgan 1800" an advanced steampunk styled 'particle organ' and the new particle texture store!
Sham Omlet
Registered User
Join date: 26 Mar 2006
Posts: 9
08-20-2006 15:43
Thank you all for all of your help.

Azurei Ash - I implemented your ideas, thank you very much for your time and help, I really appreciate it. Everything works, and is satisfactory! The script is still in testing, I will post all parts once it is complete.