I fiddled out this morning the code for birds. Now I'm happy it is working. It seems to me, that ent_animate is not working with pure vertex-animated models. *hehe* needed two hours to find that out.

Just place the model in WED (somewhere in the air, not more than 500 quants above the player (otherwise, change the distance in the alpha_ratio commandline)), attach the anml_moewe action to it and enjoy.

Code:

sound moewe_01 = "moewe_einzeln.wav";

define alpha_ratio, skill10;

action anml_moewe
{
var start_pos;
var bird_speed = 15; // flying speed
var flying_distance = 250; // flying distance from start position
var target_angle;
var moewe_schrei; // handle for sound

my.polygon = off; // set this on, if you want to interact with the bird
my.transparent = on;

my.pan = int(random(360)+1);
vec_set (start_pos.x, my.x); // store the initial position of the bird
vec_set (target_angle.pan, my.pan);

while (me)
{
if((int(random(100)) < 5) && (!snd_playing(moewe_schrei)))
{
moewe_schrei = ent_playsound(my, moewe_01, 300);
}

my.alpha_ratio = (3000 - (vec_dist(player.x, my.x))) / 450;
my.alpha = my.alpha_ratio * 100;
temp.x = bird_speed * time;
temp.y = 0;
temp.z = 0;

c_move (my, temp, nullvector, ignore_passable);

if(my.pan < target_angle.pan - 2)
{
my.pan += 1 * time;
my.flag1 = on;
}
else
{
my.flag1 = off;
}
if(my.pan > target_angle.pan + 2)
{
my.pan -= 1 * time;
my.flag1 = on;
}
else
{
my.flag1 = off;
}

my.skill40 = vec_dist(my.x, start_pos);

if ((my.skill40 > flying_distance) && (my.flag1 == off))
{
vec_set(temp,start_pos);
vec_sub(temp,my.x);
vec_to_angle(target_angle,temp);
}

if(my.skill20 <= 1)
{
my.anim_type = random(100) + 1;
}
if(my.anim_type < 70)
{
ent_animate(me, "flap", my.skill20, anm_cycle); // animate the bird
my.skill20 += 9 * time; // animation speed
my.skill20 %= 100; // loop animation
}
else
{
ent_animate(me, "glide", my.skill20, anm_cycle); // animate the bird
my.skill20 += 4 * time; // animation speed
my.skill20 %= 100; // loop animation
}

wait(1);
}
}



Maybe it is not the cleanest code you've ever seen, but it works fine for me. And maybe someone can use it.

RAR-File (includes model (untextured), code and sound) (18 kb)

Video (~ 3MB, AVI)

EDIT: Oups, used ent_cycle in the code... updated to ent_animate

EDIT2: Note: I've forgotten to define my.alpha_ratio. Define it at a free skill of your choice. I've added this in the postet code, line 3.

Last edited by LordRathan; 06/23/06 16:13.