|
2 registered members (steyr, alibaba),
534
guests, and 4
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Blending [looks like no one have the unswer]
#317990
04/04/10 05:14
04/04/10 05:14
|
Joined: May 2009
Posts: 5,367 Caucasus
3run
OP
Senior Expert
|
OP
Senior Expert
Joined: May 2009
Posts: 5,367
Caucasus
|
Yesterday, I've started the same topic in Lite-C Programming, but looks like no one can unswer  So thats why I'm making new topic here. My weapons have many animations (run,idle,hoslster,draw,shoot,reload,aim), so I need smooth changing bettwen animations, thats why I want to use ent_blend, from Wiki I got and changed this script to my own needs: ANIMATIONS.C
/*
call in player while loop
handle_animation(1);
*/
#define nullframe -2
#define blend -1
#define stand 0
#define run 1
#define shoot 2
#define reload 3
#define draw 4
#define holster 5
#define animate skill31
#define animate2 skill32
#define animblend skill33
#define currentframe skill34
#define blendframe skill35
function handle_animation(var animation_speed)
{
if(animation_speed <= 0) animation_speed = 1;
if(my.animblend != blend && my.blendframe != nullframe) { my.animate2 = 0; my.animblend = blend; }
if(my.animblend == blend)
{
if (my.currentframe == stand) ent_animate(my, "idle", my.animate, ANM_CYCLE);
else if(my.currentframe == run) ent_animate(my, "run", my.animate, ANM_CYCLE);
else if(my.currentframe == shoot) ent_animate(my, "shoot", my.animate,0);
else if(my.currentframe == reload) ent_animate(my, "reload", my.animate,0);
else if(my.currentframe == draw) ent_animate(my, "draw", my.animate,0);
else if(my.currentframe == holster) ent_animate(my, "holster", my.animate,0);
if (my.blendframe == stand) ent_blend("idle",0,my.animate2);
else if(my.blendframe == run) ent_blend("run",0,my.animate2);
else if(my.blendframe == shoot) ent_blend("shoot",0,my.animate2);
else if(my.blendframe == reload) ent_blend("reload",0,my.animate2);
else if(my.blendframe == draw) ent_blend("draw",0,my.animate2);
else if(my.blendframe == holster) ent_blend("holster",0,my.animate2);
my.animate2 += 45 * time_step;
if(my.animate2 >= 100)
{
my.animate = 0;
my.animblend = my.blendframe;
my.blendframe = nullframe;
}
}
//
switch(my.animblend)
{
case stand:
ent_animate(my,"idle",my.animate,ANM_CYCLE);
my.animate += 2 * animation_speed * time_step;
my.animate %= 100;
my.currentframe = stand;
break;
case run:
ent_animate(my,"run",my.animate,ANM_CYCLE);
my.animate += 10 * animation_speed * time_step;
my.animate %= 100;
my.currentframe = run;
break;
case shoot:
ent_animate(my,"shoot",my.animate,0);
my.animate += 20 * animation_speed * time_step;
my.currentframe = shoot;
if(my.animate >= 100)
{
ent_animate(my,"shoot",100,0);
my.animate = 100;
my.blendframe = stand;
if(vec_dist (player1_pos.x, player2_pos.x) != 0 && (key_w || key_s || key_a || key_d))
{
if(key_shift == 1) my.blendframe = run;
}
}
break;
case reload:
ent_animate(my,"reload",my.animate,0);
my.animate += 15 * animation_speed * time_step;
my.currentframe = reload;
if(my.animate >= 100)
{
ent_animate(my,"reload",100,0);
my.animate = 100;
my.blendframe = stand;
if(vec_dist (player1_pos.x, player2_pos.x) != 0 && (key_w || key_s || key_a || key_d))
{
if(key_shift == 1) my.blendframe = run;
}
}
break;
case draw:
ent_animate(my,"draw",my.animate,0);
my.animate += 10 * animation_speed * time_step;
my.currentframe = draw;
if(my.animate >= 100)
{
ent_animate(my,"draw",100,0);
my.animate = 100;
my.blendframe = stand;
if(vec_dist (player1_pos.x, player2_pos.x) != 0 && (key_w || key_s || key_a || key_d))
{
if(key_shift == 1) my.blendframe = run;
}
}
break;
case holster:
ent_animate(my,"holster",my.animate,0);
my.animate += 15 * animation_speed * time_step;
my.currentframe = holster;
if(my.animate >= 100)
{
ent_animate(my,"holster",100,0);
my.animate = 100;
my.blendframe = stand;
if(vec_dist (player1_pos.x, player2_pos.x) != 0 && (key_w || key_s || key_a || key_d))
{
if(key_shift == 1) my.blendframe = run;
}
}
break;
}
if(my.animblend != blend && my.blendframe != nullframe) { my.animate2 = 0; my.animblend = blend; }
}
function main_anim()
{
if(vec_dist (player1_pos.x, player2_pos.x) != 0 && (key_w || key_s || key_a || key_d) && force_run > 5 && climb == 0 && crawling == 0)
{
if(my.animblend == stand)
{
if(key_shift == 1) my.blendframe = run;
}
}
else
{
if(my.animblend > stand)
{
my.blendframe = stand;
}
}
}
Here is how I'm tring to use it:
action v_usp()
{
weapon = me;
set(my,ZNEAR);
while(me == weapon)
{
if ((mouse_left ==1)&&(usp_rdy ==1))
{
if (usp_clip > 0)
{
usp_shoot(1);
while(mouse_left){wait(1);}
}
}
main_anim();
handle_animation(1);
wait(1);
}
}
function usp_shoot(t)
{
if (t ==1)
{
snd_play(deagle_shot_snd,100,0);
my.blendframe = shoot;
my.animate2 = 0;
my.animblend = blend;
ent_create(bullet_mdl,camera.x,bullet);
}
}
When I try to do this way, there ia only runing and idle animations are working  but how do I add shoot,reload,draw etc. Really need your help. May be there is an other way to make smooth animation changings?
|
|
|
Re: Blending [looks like no one have the unswer]
[Re: 3run]
#318223
04/06/10 07:21
04/06/10 07:21
|
Joined: Aug 2008
Posts: 482
bart_the_13th
Senior Member
|
Senior Member
Joined: Aug 2008
Posts: 482
|
Ok, here's the code. I have a run animation, walk animation and stand animation for the lower body, and run, walk stand, reload and shoot animation for upper body so it may seems complicated(since I use 1 model)
blendwalk+=time_step*30;
if(blendwalk>100) blendwalk=100;
blendrun+=time_step*30;
if(blendrun>100) blendrun=100;
blendshoot+=time_step*30;
if(blendshoot>100) blendshoot=100;
if(key_shift == 1 && aim==0) //is running
{
if(run==0) blendrun=0;
run=1;
vec_scale(speed.x,2);
}
else
{
if(run==1) blendrun=0;
run=0;
}
result=c_move(me, nullvector, vector(-speed.x*move_dest.x,-speed.y*move_dest.y,0), IGNORE_PASSABLE | GLIDE);
if(result>0) //is moving
{
if(aim==0) //is not shooting
{
if(key_shift) // is not running
{
ent_animate(me,run_str,total_ticks*5,ANM_CYCLE);
}
else
{
ent_animate(me,"walk",total_ticks*5,ANM_CYCLE);
}
if(blendshoot<100) ent_blend("shoot",0,100-blendshoot);//blend from shooting to walking/running
}
else
{
ent_animate(me,"shoot",my.recoil_effect,ANM_CYCLE);
if(blendshoot<100)
{
if(key_shift) ent_blend(run_str,total_ticks*5,100-blendshoot);//blend from running to shooting
else ent_blend("walk",total_ticks*5,100-blendshoot); //blend from walking to shooting
}
}
if(my.reloading>0) //is reloading
{
if(my.reloading<10) ent_blend(reload_str,100-my.reloading,(my.reloading)*10);
if(my.reloading>=10 && my.reloading<=80) ent_animate(me,reload_str,100-my.reloading,ANM_CYCLE);
if(my.reloading>80) ent_blend(reload_str,100-my.reloading,100-(my.reloading%20)*5);
}
if(key_shift && aim==0) ent_animate(me,"legrun",total_ticks*10,ANM_CYCLE|ANM_ADD);
else ent_animate(me,"legwalk",100-(total_ticks*5)%100,ANM_CYCLE|ANM_ADD);
if(blendmove<100)
{
if(aim==0) ent_blend("stand",total_ticks*5,100-blendmove);//blend from walk/run to stand
if(aim==1) ent_blend("shoot",0,100-blendmove);//blend from walk/run to shoot
}
}
else
{
if(aim==0)
{
ent_animate(me,"stand",0,0);
if(blendshoot<100) ent_blend("shoot",0,100-blendshoot);//blend from stand to shoot
}
else
{
ent_animate(me,"shoot",my.recoil_effect+=1,ANM_CYCLE);
if(blendshoot<100) ent_blend("stand",0,100-blendshoot);//blend from shoot to stand
}
if(my.reloading>0)
{
if(my.reloading<10) ent_blend(reload_str,100-my.reloading,(my.reloading)*10);
if(my.reloading>=10 && my.reloading<=80) ent_animate(me,reload_str,100-my.reloading,ANM_CYCLE);
if(my.reloading>80) ent_blend(reload_str,100-my.reloading,100-(my.reloading%20)*5);
}
if(blendmove<100)
{
if(run==1) ent_blend(run_str,total_ticks*5,100-blendmove);//blend from shoot to run
if(run==0) ent_blend("walk",total_ticks*5,100-blendmove);//blend from shoot to walk
}
}
I'm also thinking about reducing the code using string and str_xxx but I still have no time, but I think this will give you the picture about ent_blend with some state/pose
|
|
|
|