Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Script for wings from a novice's perspective

Kats Kothari
Disturbingly Cute
Join date: 14 Aug 2003
Posts: 556
01-20-2005 15:02
I am still learning how to script. I get the hang of scripts related to textures and colors, sounds, animated objects (even a bit about particles), but I am still learning scripts related to physics, movement, etc., so please be gentle. ;)

I have been trying to understand how to make wings move on an object. A long time ago I made some wings for a bird for a friend, but I had to use textures and the script to animate them, but it doesn't look quite right. I wanted to remake the bird for her, but I wanted to use prims instead of basing the wings on animated textures (which were out of synch to begin with). What would I need and need to learn to make flapping wings,wagging tails, or any timer based movement (if that's what it does)? Is the script similar to the door script but using some sort of timer event? Can the wings/tails be linked to the object?

P.S. I know that there was a similar thread started not too long ago, but I didn't understand much of the tips that were given, being still a novice in the art of scripting.
_____________________
Maker of many kawaii items: Dolls, huggable plushies, and purses with cute critters.
Visit Kats' Kreatures for a better look and feel free to explore! =^_^=
Kats' Kreatures Gualala (140,9)


"The cat is cryptic, and close to strange things which men cannot see..."
- H.P. Lovecraft
Upshaw Underhill
Techno-Hobbit
Join date: 13 Mar 2003
Posts: 293
01-20-2005 15:35
Hey Kats ^_^

Lemme try to give an example via ASCII graphics

CODE



1\ /1
\ /
2-------2
/ \
/ \
3 3


this is looking at the nose of the bird
1 is a set of prims representing the up postion of the wings
2 is a flat set
3 is the downward 'flapped' set

you'd still texture the wings however you'd like and you can have as many prims for each 'set' as you like.

in the main prim you'd have a counter which bounces between 1 and 3
it sends llMessageLinked and the numbers

in each of the prims for the wings you'll have a link_message event which listens for its number

CODE

integer X = 1; // whichever wing prim I'm a part of
default
{
link_message(integer sender,integer num,string str, key id)
{
if (num == X)
{
llSetAlpha(ALL_SIDES,1.0);
}
else
{
llSetAlpha(ALL_SIDES,0.0);
}
}
}

(I'm at work so this might not compile but it's close) :D

This is the most effective way to do it especially if you want multi-prim wings.
There are other ways using llSetRot commands but rotations generally cause me to reach for the Motrin immediately.

L8r,
UU

P.S. I'll do better code sometime tonight (including the control script) and drop it on you later if you like Kats.
Rysidian Rubio
Ruby Red Head
Join date: 14 Jan 2004
Posts: 263
01-20-2005 16:09
One of the ways you can do this is to think of it like an animation or cartoon. you have a seperate wing for eash position that the wings will move through, so if they need to appear to flap, you might want 3 wing positions, one wing pointing up (1), then straight across (2), then down (3) to simulate a flapping pattern.

Where the scripting comes in is to make only 1 of those 3 wings visible at a time, then cycle through which one is visible. So a full cycle would see the following

*wing 1 visible, wings 2 & 3 invisible then
*wing 2 visible, wings 1 & 3 insivible
*wing 3 visible, wings 1 & 2 invisible
*wing 2 visible, wings 1 & 3 invisible

So it will look like the wing is moving, but really it's not moving at all.

The Script is fairly straightforeward, just link all of the prims that up all of the wings, and put the wing script into each prim, and the controller into one prim. All you need to change is the WINGNUM variable in the WiNG PRIM SCRIPT, which you change depending on which wing the prim is part of (wing 1,2 or 3 as above).
CODE
//WING PRIM SCRIPT
integer WINGNUM = 1; //Change this depending on which wing this prim is part of.

default
{
link_message(integer sender_num, integer num, string str, key id)
{
if (num == WINGNUM)
{
llSetAlpha(1.0, ALL_SIDES);
}
else
{
llSetAlpha(0, ALL_SIDES);
}
}
}
CODE
//WING CONTROLLER SCRIPT
integer WINGNUMBER = 1;
integer UP = FALSE;
default
{
state_entry()
{
llListen(10,"","",""); //listen to owner
}

listen(integer channel, string name, key id, string message)
{
if (id != llGetOwner())
return;

if (llToLower(message) == "flap")
{ //start flapping
llSetTimerEvent(1);
WINGNUMBER = 1;
}
else if (llToLower(message) == "stop")
{ //stop flapping
llSetTimerEvent(0);
WINGNUMBER = 1; //Change this if you want a different wing to be the one that shows when not flapping
llMessageLinked(LINK_SET,WINGNUMBER,"","");
}

}

timer()
{
llMessageLinked(LINK_SET,WINGNUMBER,"","");
if (WINGNUMBER == 3)
{
WINGNUMBER = 2;
UP = TRUE;
}
else if (WINGNUMBER == 1)
{
WINGNUMBER = 2;
UP = FALSE;
}
else if (WINGNUMBER == 2)
{
if (up)
WINGNUMBER = 1;
else
WINGNUMBER = 3;
}
}
}
These scripts haven't been tested so if they don't work let me know (i'm at work)
Upshaw Underhill
Techno-Hobbit
Join date: 13 Mar 2003
Posts: 293
01-20-2005 16:13
and by these posts you can see who's a programmer and who has more time at work :D

Thanks Rys :)

L8r,
UU
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
01-20-2005 16:23
Got that right, UU.

To avoid a repost, Kats, you can view my suggestions here.

Rysidian explained my first suggestion nicely. To add to Rysidian's point, try texture animations between several prims in this manner for a smoother effect.
_____________________
---
Rysidian Rubio
Ruby Red Head
Join date: 14 Jan 2004
Posts: 263
01-20-2005 17:16
From: Upshaw Underhill
and by these posts you can see who's a programmer and who has more time at work :D
LOL
You got that right Upshaw. I'm so bored at work today with nothing to do, hehe.
Kats Kothari
Disturbingly Cute
Join date: 14 Aug 2003
Posts: 556
01-20-2005 20:36
You guys rock! :D
You made it sound very simple and I understood it without it making my head explode. Thank you very much.

BTW...Have you considered giving scripting classes?
_____________________
Maker of many kawaii items: Dolls, huggable plushies, and purses with cute critters.
Visit Kats' Kreatures for a better look and feel free to explore! =^_^=
Kats' Kreatures Gualala (140,9)


"The cat is cryptic, and close to strange things which men cannot see..."
- H.P. Lovecraft
Upshaw Underhill
Techno-Hobbit
Join date: 13 Mar 2003
Posts: 293
01-21-2005 00:58
One thing we did find when testing though Rys, in the timer event:
WINGNUMBER == 2;
should be WINGNUMBER = 2;
(or 1 or 3 of course)

I do the same thing myself.
my mnemonic is
X equals 2? (equals plural)
or X is equal to 2 (equals singular)

L8r,
UU
Rysidian Rubio
Ruby Red Head
Join date: 14 Jan 2004
Posts: 263
01-21-2005 01:07
From: Upshaw Underhill
One thing we did find when testing though Rys, in the timer event:
WINGNUMBER == 2;
should be WINGNUMBER = 2;
(or 1 or 3 of course)
LOL thanks for pointing that out Upshaw. I usually get it the other way around, hehe. I'll edit it. :)
Ricky Zamboni
Private citizen
Join date: 4 Jun 2004
Posts: 1,080
01-21-2005 07:06
An addition off the top of my head....

If you want to have lot of wing positions to make the animation appear more smooth, and don't want to fiddle about with 50 if-the-else's, modify the wing controller like such:
CODE

// WING CONTROLLER SCRIPT
integer TOPWING = 1;
integer BOTTOMWING = 50;
integer UP = 0;

<snip>

timer()
{
llMessageLinked(LINK_SET,WINGNUMBER,"","");
if (WINGNUMBER == TOPWING)
{
UP = 0;
}
else if (WINGNUMBER == BOTTOMWING)
{
UP = 1;
}

WINGNUMBER = WINGNUMBER + 1 - 2 * UP;
}


This is untested, but should work. :)
_____________________
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
01-21-2005 07:39
CODE
// link message brodcast counter
// timer used to create loop: broadcasts the count on link message, count will be in a range defined by minCount and maxCount. count will count up to maxCount, then count back down to minCount. At witch point it will repeate the prossess
//this vertion will only count by 1 or -1

//global veriables
//settings
integer minCount = 0;
integer maxCount = 50;
//dynamic
integer count = minCount;
integer change = 1;

default
{
touch_start(integer total_number)
{

}

// time represents an iteration in a loop. Controller is count
// note count >= maxCount is up at the top as unnessiary error correction
timer()
{
if ( count >= maxCount)
{
change = -1;
}
else if ( count <= minCount )
{
change = 1;
}

llMessageLinked ( LINK_SET, count, "", "" );

count = count + change;
}

}
Ricky Zamboni
Private citizen
Join date: 4 Jun 2004
Posts: 1,080
01-21-2005 07:49
I add 1 and subtract 2*UP so I basically get a flag with a value +/-1 so I can increment/decrement with the same line of code.

The "WINGNUMBER = WINGNUMBER + 1 - 2 * UP" statement will increment when the wing is going down (i.e. UP == 0). Once it hits the bottom (sets UP = 1), it will decrement until it hits the top (and sets UP = 0).

It looks to me like your code will simply do a wraparound -- once the wing reached the bottom, it will immediately jump back to the top, giving a discontinuous animation.
_____________________
Kurt Zidane
Just Human
Join date: 1 Apr 2004
Posts: 636
01-21-2005 08:14
woops your totally right, I wasn't paying attention to the order of operations in math. fixed
Shadus Stonebender
Evil Monkey
Join date: 17 Jan 2005
Posts: 37
01-21-2005 10:05
How do you check and see if someone is flying?
Kats Kothari
Disturbingly Cute
Join date: 14 Aug 2003
Posts: 556
01-21-2005 16:46
Just wanted to thank you all for your help and post a pic of the bird that I remade using this wonderful script and the pet script. :)
_____________________
Maker of many kawaii items: Dolls, huggable plushies, and purses with cute critters.
Visit Kats' Kreatures for a better look and feel free to explore! =^_^=
Kats' Kreatures Gualala (140,9)


"The cat is cryptic, and close to strange things which men cannot see..."
- H.P. Lovecraft
Upshaw Underhill
Techno-Hobbit
Join date: 13 Mar 2003
Posts: 293
01-21-2005 22:38
Welcome Kats ^_^


Shadus, check this page on the Wiki

llGetAgentInfo

L8r,
UU
Shadus Stonebender
Evil Monkey
Join date: 17 Jan 2005
Posts: 37
01-22-2005 15:26
From: Upshaw Underhill
Welcome Kats ^_^


Shadus, check this page on the Wiki

llGetAgentInfo

L8r,
UU


Thanks much :)