Saturday, March 17, 2007

Day 174: Creating Particle Effects Part 3

In Creating Particle Effects Part 1 and Part 2, we talked about the Particle Script and how to tweak some of its settings to make fire, party, and watery effects using light particles only.

In this part of the tutorial series, we are going to create 2 particle effects using textures: underwater bubbles and butterflies.

You will need the "Smokey Feet (L)" object from Part 2. You will also need the "Particle Texture - Bubble" and "Particle Texture - Butterfly" textures. You can pick all of these items up for free from Particle Scripts folder at Sirena Hair (Click on Search, select the Places tab, and enter "sirena" as the keyword).

If you dont want to make these 2 particle gadgets, you can still see what they do by picking them up from the Particle Scripts folder at Sirena Hair & Fashion.


1. Bubble Blower



Unless you are a mermaid, you are probably going to blow bubbles when you are underwater. Even mermaids can blow bubbles if they want :) So we are going to make an attachment that makes bubbles come out of your nose.

(Yes, in case you are wondering, this is just an excuse for me to be a mermaid today :P)

Bubble particle emitters are very useful for simulating water in Second Life. After all, there isnt really any "water" in SL. When you go below "sea level" in a sim, your view gets murky. You can walk, talk, fly and dance like you normally do on land. So bubbles, fishes, and sea plants help provide a sense that you are actually underwater.



For a good underwater place, come to Cave Cult at Cave Rua, a popular spot for mermaids to watch human SCUBA divers :) There are lots of bubble and fish particle emitters here. Click on Search, select the Places tab, and enter "cave cult" as the keyword. The SLURL is Rua (167,44,7).

In the previous particle tutorials, we basically used colored lights for particles to simulate flame, shower water, and fog/smoke. To make bubbles look more realistic, we need to apply a texture to the particles.

So lets make some bubbles :)

Find the "Smokey Feet (L)" object from Part 2 of this tutorial series in your Inventory. Right-click on "Smokey Feet (L)" and select "Copy". Right-click on "Smokey Feet (L)" again and select "Paste". Now you should have 2 "Smokey Feet (L)" objects in your Inventory.

Right-click on one of the "Smokey Feet (L)" objects and select "Rename". Change the name to "Bubble Blower".

Right-click on "Bubble Blower", select "Attach To >", and "Mouth".



OK, as soon as you do this, you are going to see smoke from your chest. :P

We need to make the Bubble Blower visible so we can change the script inside.



In the Chat box, say "/22 smoke show". You should be able to just make out the red disc in the smoke somewhere. If you cant see it very well, just move your avatar a little bit to clear the smoke and try a pose that moves your avatar's head.

Right-click on the red Bubble Blower and select Edit. Select the Object tab and enter the following settings:

Size X: 0.050
Size Y: 0.050
Size Z: 0.050



(Dont laugh! :P)

Now drag the Blue arrow to move the Red ball to your mouth. The display at the top of your screen should read about: X:0.000 Y:0.000 Z:0.000.

Select the Content tab.

Look for the "Particle Texture - Bubble" texture file in your Inventory (the one in the Particle Scripts folder that you got from Sirena Hair & Fashion). Drag and drop the "Particle Texture - Bubble" texture file from your Inventory into the Content tab of the Bubble Blower.

Right-click on the "Particle Script - Smokey Feet" script in the Content tab of the Bubble Blower. Select "Rename". Change the name to "Particle Script - Bubble Blower".



Double-click on the "Particle Script - Bubble Blower" script to open and edit it.













Apply the following changes to the script:

integer pattern = PSYS_SRC_PATTERN_ANGLE_CONE;

float age = 5.0;
float maxSpeed = 0.3;
float minSpeed = 0.03;
string texture = "Particle Texture - Bubble";

float startAlpha = 1;
float endAlpha = 0;
vector startColor = <1,1,1>;
vector endColor = <1,1,1>;
vector startSize = <0.05,0.05,0.05>;
vector endSize = <0.05,0.05,0.05>;
vector push = <0,0,0>;

float rate = 5;
float radius = 0.03;
integer count = 25;
float outerAngle = 3;
float innerAngle = 0.9;
float beginAngle = 0.4;
float endAngle = 0;

Click on the "Save" button to save your changes, and close the script window.

(Thanks Taffy, for mentioning that you can just use the texture file name instead of Asset UUID! That makes things so much easier! :D)



(Its still not funny! :P)

You should now see bubbles come out of your mouth :)

To make the Bubble Blower invisible again, just say "/22 smoke hide" in the Chat box.

Thats it! You are blowing bubbles underwater.

You can tweak this script and make bubble jets for aquariums or an underwater scene. If you are a human, you can also build yourself a SCUBA or snorkeling outfit :)


2. Butterflies

OK...time to dry off my tail... :(



Have you ever seen a resident walk around with butterflies, dragonflies, or other pretty things flying around them? This is, of course, a particle effect.

We are going to make a butterfly emitter that creates butterflies around you.

Find the "Bubble Blower" object from above in your Inventory. Right-click on "Bubble Blower" and select "Copy". Right-click on "Bubble Blower" again and select "Paste". Now you should have 2 "Bubble Blower" objects in your Inventory.

Right-click on one of the "Bubble Blower" objects and select "Rename". Change the name to "Butterfly Emitter".

Right-click on "Butterfly Emitter", select "Attach To >", and "Left Shoulder".

When you do this, bubbles are going to start coming from your left shoulder. Dont ask me where that's coming from :P

We need to make the Butterfly Emitter visible so we can change the script inside. In the Chat box, say "/22 smoke show".

Right-click on the red Butterfly Emitter on your left shoulder and select Edit.

Select the Content tab.

Look for the "Particle Texture - Butterfly" texture file in your Inventory. Drag and drop the "Particle Texture - Butterfly" texture file from your Inventory into the Content tab of the Butterfly Emitter.

Right-click on the "Particle Script - Bubble Blower" script in the Content tab of the Butterfly Emitter. Select "Rename". Change the name to "Particle Script - Butterfly Emitter".

Double-click on the "Particle Script - Butterfly Emitter" script to open and edit it.

Apply the following changes to the script:

integer pattern = PSYS_SRC_PATTERN_ANGLE_CONE;

key target = "self";

float age = 10.0;
float maxSpeed = 0.5;
float minSpeed = 0.05;
string texture = "Particle Texture - Butterfly";

float startAlpha = 1;
float endAlpha = 1;
vector startColor = <1,1,1>;
vector endColor = <1,1,1>;
vector startSize = <0.07,0.07,0.07>;
vector endSize = <0.07,0.07,0.07>;
vector push = <0,0,0.2>;

float rate = 4;
float radius = 1;
integer count = 1;
float outerAngle = 3;
float innerAngle = 0.9;
float beginAngle = PI_BY_TWO;
float endAngle = PI_BY_TWO;

Click on the "Save" button to save your changes, and close the script window.

You should see butterflies flying around you!

To make the Butterfly Emitter invisible again, just say "/22 smoke hide" in the Chat box.


3. Where Did Those Butterflies Come From?

We added a few interesting things to the Butterfly Emitter to make the butterflies more interesting.

The first thing you probably noticed was the target = "self" line. This makes the particles want to move towards the particle emitter object, in this case, the invisible red ball on your left shoulder.

But where are the butterflies coming from?

The radius = 1 line means the butterfly "particles" are created 1M away from the particle emitter.



We are using an Angle Cone with beginAngle and endAngle equal to PI_BY_TWO (or PI divided by 2). Where do you think I came up with this one? Yep, the Angle display at the Particle Laboratory.

With this particular angle setting, the butterflies would fly directly outward (no up or down movement). They will start 1M away from the particle emitter, then turn around and head back towards the particle emitter.

However, we added 1 more thing: push = <0,0,0.2>. This provides a little upward push to all butterflies, while they are flying out. This makes them fly around in a nice loop (versus using a smaller angle cone).

If you want different color butterflies (or even different things) around you, put multiple prims together, with a different script in each prim.

Have fun with your new particles :)




numly esn 39942-071006-316551-10

© 2007 All Rights Reserved.

12 comments:

Taffy Allandale said...

Hey, Natalia! (ever feel like you have a twin out there in SL?)

Question: instead of using the UUID - isn't it easier to use the name of the particle - i.e. "bubble" or "butterfly" ? The reason I ask is I went to a class where they showed us how to make a "Poofer" for when an av TPs out of a place and it uses the name instead of UUID.

~~Tootles~~
Taffy

Anonymous said...

I saw another tutorial from secondlifehowto.com

HowTo: Experiment With Particles December 16th, 2006 That demonstrates creating particles with butterflies...

Trouble Houston said...

Nat:
I love scuba diving in cave rua.
Have you visit outer space and blue moon, and ice world there?
If not you should, Are fantastic.

Tr.

SLNatalia said...

Taffy, you are absolutely right! I got used to using that long Asset thing and never just tried the name! I guess we can use the name as long as the actual texture is in the particle emitter :) That makes things so much easier! Thank you so much Taffy! :)

Dear Anonymous, thats good to know! I will go check it out :)

Trouble, I um...*heard* there were lots of mermaids in Cave Rua... not that there are such things as mermaids :P

Ive been to ice world, but I dont remember outer space or blue moon...I have to go back and look :) Thank you for telling me!

Anonymous said...

Dear Natalia,

Thank you very much for these great tutorials! I've almost finished them all, thanks to you 8^)

Would it be possible for you to make a part 4 to this series, with a command to channel 22 to emit the particles only when told to? Or maybe on a timer?

Thanks and HUGS
JJ

SLNatalia said...

JJ, there is a script in the Particle Scripts folder called "Cancel Particles". This has the code for stopping particles from coming out.

I guess the script could be modified to "listen" for a command to stop the particles and start them again...

Come on...dont you want butterflies around you ALL the time? :)

Christina said...

Hi.
I'm having a little trouble
I went to Sirena Hair & Fashion to look for the Particle Scripts folder
but can't seen to find it could you tell me where it might be

SLNatalia said...

Christina, the Particle Scripts are in the Tutorial Supplies area, under the giant mermaid sign :)

Chimi said...

Hi! Wow...really good tutorial. I love my new butterflies & bubbles. The bubbles will look great in scuba diving :P.
I just changed a little thing: Some words in the script. That way I have to say, for example, "/22 bubble hide" instead of "/22smoke hide", to hide the bubbles. I did the same with the butterflies :).
Scripting can be confusing :S
But the tutorial was very clear.

Natalia Zelmanov said...

Chimi, Im glad that it worked, esp for diving :) Have fun ;)

Brighton said...

Thank you for this very generous blog :) One thing i dicovered wtih your particle script is that if you give an object with the script in it to another Avi, that Avi is not recognized as the new owner by the script. This means the other Avi will not be able to control the emitter by saying f.ex. 'bubbles on', 'bubbles off'. Pasting these lines into the script below the 'state entry' function will solve this problem:

on_rez(integer p)
{
//reset, in case new owner
llResetScript();

}

Natalia Zelmanov said...

Brighton, thank you so much for the suggestion! Eek, never though of that :P