Jump to content

Need a little help with scripting


Lumychan
 Share

You are about to reply to a thread that has been inactive for 4509 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello everyone.

I'm fairly new to second life and just started building stuff and descovering scripting.

This is what I'm currently working on, and I need help with a few things.

project.png

It's steampunk-ish and I got puffs of smoke to come out of the pipe. But I wasnted to do some mroe things and don't know how:

1. I wanted to make the cogs turn, but have no idea how to do so

2. Wanted to make both the cog movement as well as the smoke start/stop when touching the object

Bonus question (:D): Should I add sound to this?

 

Thank you very much for the help and hope I managed to post this in the correct forum...

Link to comment
Share on other sites

Touch on-off needs a global 'on' flag that toggles each time someone touches the thing.  Sound is easy as long as you put the effect in the object's contents.  Rotation is a BIG subject but I recommend you start by looking at llTargetOmega()

 

integer On;default{	touch_end(integer HowMany){		if(On = !On){			// <--- Put your smoke llParticleSystem() instruction here			// <--- Start continuous-play using llLoopSound()			// <--- llTargetOmega() for rotation		}else{			llParticleSystem([]);			llStopSound();			llTargetOmega(ZERO_VECTOR, 0.0, 0.0);		}	}}

 

Once you've figured-out llTargetOmega() you can get more creative using llSetLinkPrimitiveParamsFast([PRIM_OMEGA, ...]).  Note that Omega is for apparent rotation only - it looks good but is only a visual effect, not 'really' moving the prims at all.  llSetRot() and other functions do that job but the relative rotations of the world, root and child-prims all make it a little bit of a mind-bender.  Start with omega or you'll go mad, MAD I say, muhahahahaaa!

Link to comment
Share on other sites

In order to make the cogs turn you either use llTargetOmega which will result in a visual effect in the viewer but wont actually make it turn for the server (if the cogs are non-physical) or some form of llSetRot - probably in combination with llSetPos. These 2 actually make a rotation or a change in location on the server side as well. For both you will have to figure out whether the local rot/pos are to be changed ot the global ones. If that sounds confusing, it's partly because it's a little tricky - it's one of the more difficult areas of LSL. Well, at least for me. If you are new to scripting, you will need to fidle around with rotations and positions a bit. Pages that may help you are the explanations of Void Singer or the Windmill tutorial.

As fat as smoke and sound on touch are concerned, here is a little example:

list glParticles = []; //the parameters for your smoke go herestring gsSound = ""; //put the name of the sound hereinteger giOnOff;default {	touch_end(integer num_detected) {		if (!giOnOff) { //are sound and smoke on? If no, turn them on			llLoopSound(gsSound, 1.0);			llParticleSystem(glParticles);		} else { //if yes, turn them off			llStopSound();			llParticleSystem([]);		}		giOnOff = !giOnOff; //toggle the giOnOff value	}}

 I pass on the bonus question ;)

Link to comment
Share on other sites

*sigh*

SO I spent all these hours constantly going around with the script and managed to get abolutely nowhere.

For as much as I try, I can never get the cog to rotate properly. Now, I did pick up some questions alongt he way:

-What is an axis and how can I set it to be in the middle of the cog, so the cog spins around it?

-What is a child prim and how does this affect rotation?

Link to comment
Share on other sites

  • When you edit an object, you usually see a blue, a red and a green line going through it - these are the 3 axes x, y and z.
  • Objects can be made up of several prims that are linked. In such a link set, one prim is the parent, the others are the children (usually the children have a blue frame in edit mode, the parent or root a yellow one). A rotation or a movement can be relativ to the root or relative to the region. By and large, chidren rotate or move relative to the object they belong to and the root relative to the region - by and large. LSL is a bit tricky here - you will have to read the arcticles, the documentation of the functions and then fiddle ;)

MMuch moe could be said in response to your questions, but I think the answers give you an idea.

Link to comment
Share on other sites

Movement and especially rotation of multi-prim objects is not trivial.  You want different prims to move in different directions around different (other) prims in different planes and, probably, at different speeds.  SL rotations use quaternions so a rotation looks something like "<-0.37,1.2,2.04,-0.0>".  There are four dimensions or axes in a quaternion (hence the name): x, y, z and s and all values are in radians so a semi-circle is PI radians.

Got that?  Starting to understand why we said not to go there? Here's the easy bit (well, easier, anyway) ...

llTargetOmega() is the shallow-end of rotations partly because there are only the 3 'normal' axis of rotation: x, y and z.  Think of them in 3D as north/south, east/west and up/down.  Think of a prim and 'z' is an axis/axle/line running up and down through its middle.  If you rotate something "around the z axis" (axle) you give it a 'flat' spin, like a dancer pirouetting.  If instead you rotate it around the x (or y) axis it will have an 'upright' movement, more like a windmill. The only difference between rotating x or y is whether the windmill 'faces' north/south or east/west, but that's the point; there isn't any difference in the z movement either, just around which axis the prim is being rotated.

If I'm sober enough not to have typed my shopping-list that should make sense.  You may need to read it a couple of times first though.

Now for the problem - I assume you want the big cogwheel in your original picture to rotate everything in a 'flat' direction.  If that's the root (main) prim then you just need something like "llTargetOmega(<0.0, 0.0, 1.0>, 1.0, 1.0)" and it'll move all the other prims along with it.  Rotating the upright cog (to the left of your picture) should be as simple as "llTargetOmega(<1.0, 0.0, 0.0>, 1.0, 1.0)" - the same thing but around the x instead of z axis.  It hardly ever is though, because that prim is linked to the ROOT prim, which is itself rotating around its z axis.

Until you've got the hang of axes and linked root and child prims you really don't want to mess with this stuff, trust me.  For now just be happy you should be able to get the main cog rotating - just make it the root and use llTargetOmega() - and you can definitely do the smoke, sound and touch on/off.

@ Ciaran & Darkie - hoorah for us; 3 replies within 2 minutes of each other, a;; saying pretty much the same thing.  Pretty high confidence factor that we actually meant it.  What jolly fine chaps we are :-)

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4509 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...