Problem: weapon attachment doesn´t fit animation

Posted By: fp

Problem: weapon attachment doesn´t fit animation - 03/11/09 21:08

i am working through the KH movement tutorial at the moment and it goes well.
I added some new animations, for example an equip / unequip sword animation and a second
stand or idle animation, because there should be another stand animation if the player has unequipped
his sword an put it on his back.
Blending the animations goes well , that means the blending or playing the animation itself is not a problem.
But now i´ve got a problem.

The weapon attachment does not fit to the animation.

that means now the code does:

he holds the sword in hand, next it is still on his back while it is playing the animation.

How can I fix it?

Can anybody help me please?

Code:
ACTION attach_weapon {
my.passable = on;
my.scale_x = 2.5;
my.scale_y = 2.5;
my.scale_z = 2.5;
proc_late();
WHILE (you != null) {
IF (equip_sword == 1)
{
vec_for_vertex(temp.x,you,152); //hand palm base
vec_for_vertex(temp2.x,you,124); //hand palm tip
vec_set(my.x,temp.x);
vec_diff(temp.x,temp2.x,temp.x);
vec_to_angle(temp.pan,temp.x);
vec_set(my.pan,temp.pan);
wait(1);
}
ELSE
{
vec_for_vertex(temp.x,you,269); //      sword on   
vec_for_vertex(temp2.x,you,720); //    his back
vec_set(my.x,temp.x);
vec_diff(temp.x,temp2.x,temp.x);
vec_to_angle(temp.pan,temp.x);
vec_set(my.pan,temp.pan);
wait(1);	
}
}
}




FUNCTION handle_movement()
.
.
.

IF(key_1 == 0 && key1_press ==1) { key1_press = 0;}
IF(equip_sword ==1)
{
IF(key_1 == 1 && key1_press ==0 && my.animblend >= stand){ my.blendframe = equip; key1_press = 1; equip_sword = 0;}
}
ELSE
{
IF(key_1 == 1 && key1_press ==0 && my.animblend >= stand){ my.blendframe = equip; key1_press = 1; equip_sword = 1;}
}

.
.
.


thank you in advance,
bye
Posted By: KDuke

Re: Problem: weapon attachment doesn´t fit animation - 03/11/09 21:29

Hi fp,

you have to wait until the unequip animation has ended before you set equip_sword to 0.

greetings
KDuke
Posted By: fp

Re: Problem: weapon attachment doesn´t fit animation - 03/11/09 22:10

thanks KDuke, but i don´t know why?

that is the animation code:

Code:
IF (my.animblend == equip) {
		var i= 0;
		ent_animate(my,"equip",my.animate,0);
		my.animate += 5 * animation_speed * time;
		my.currentframe = equip;
		IF (my.animate >= 60) 
		{
			ent_animate(my,"equip",60,0);
			my.animate = 60;
			i= 1;
		IF (equip_sword == 1)	{my.blendframe = stand;} ELSE { my.blendframe = idle;}
			IF (my.move_x != 0 || my.move_y !=0) {
			IF (key_shift == 1) { my.blendframe = walk; } ELSE { my.blendframe = run; }
			}
		}
	}


i tried it with IF(my.animate...)
but it doesn´t work.
what do i wrong?
Posted By: KDuke

Re: Problem: weapon attachment doesn´t fit animation - 03/12/09 04:23

Well...
first of why you need to wait until the animation is finished.
It is if you instantly put equip_sword on 0 the moment the program leaves this function to do other stuff (the wait(1)-statement) I guess the position of the sword is put on his back because equip_sword is 0.

Though I'm at loss how to check if an animation has finished.
I hope someone can state this.

greetings
KDuke
Posted By: fp

Re: Problem: weapon attachment doesn´t fit animation - 03/12/09 11:55

yes, got it, works now, thank you.
i did not have to do it in handle_movement(). (player.wdl)
i had to do it in handle_animation() in the animation.wld

Code:
IF (my.animblend == equip) {
		ent_animate(my,"equip",my.animate,0);
		my.animate += 5 * animation_speed * time;
		my.currentframe = equip;
		IF (my.animate >= 60) 
		{
			ent_animate(my,"equip",60,0);
			my.animate = 60;
		IF (equip_sword == 1) {equip_sword = 0;} ELSE{ equip_sword = 1;} 
		IF (equip_sword == 1)	{my.blendframe = stand;} ELSE { my.blendframe = idle;} 
			IF (my.move_x != 0 || my.move_y !=0) {
			IF (key_shift == 1) { my.blendframe = walk; } ELSE { my.blendframe = run; }
			}
		}
	}

Posted By: KDuke

Re: Problem: weapon attachment doesn´t fit animation - 03/12/09 17:49

Did you try your old code and the "extended" one you made because of my proposal?

I just would like to know if it works now because of going to animation.wld only or because of both, going to animation.wld AND checking if the animation finished.

Just would like to know if the way I was thinking was right.

greetings
KDuke
Posted By: fp

Re: Problem: weapon attachment doesn´t fit animation - 03/12/09 20:56

you were absolutly right.
the animation ends here:

IF (my.animate >= 60)
{
ent_animate(my,"equip",60,0);
my.animate = 60; /// animation ends here

Then what you have said:

IF (equip_sword == 1) {equip_sword = 0;} ELSE{ equip_sword = 1;}

bye
fp
© 2023 lite-C Forums