Animation problem in my code

Posted By: LawnmowerMan

Animation problem in my code - 03/20/11 00:00

This is my function for the player animation but I have a problem that animation speed up and slow down by themselves. I do not know where I made a mistake, please if anyone can help me.
I hope that some of the more experienced guys can help me blush

Code:
function player_animations(){
	if(my.state_player == stand)
	{
 		while (key_cuu == 0 && key_cud == 0 && key_cul == 0 && key_cur == 0) // play the "stand" animation if force keys not pressed
		{
			ent_animate (me, "stand", my.skill96, anm_cycle);
			my.skill96 += 1 * time_step;
			my.skill96 %= 100;
			wait (1); 
		}
		my.skill92 = 0;
		while(my.skill92 < 100){
			ent_animate (me, "stand", my.skill92, anm_cycle);
			ent_blend("walk", 0, my.skill42); // blend "wait" into "walk"
			my.skill92 += 10 * time_step;
			wait(1);
		}
		while (1){
			ent_animate (me, "walk", my.skill97, anm_cycle);
			my.skill97 += 1 * time_step;
			my.skill97 %= 100;
			wait (1); 
		} 	
 	}
	if(my.state_player == walk)
	{
 		while (key_cuu == 1 || key_cud == 1 || key_cul == 1 || key_cur == 1) // play the "walk" animation until the player relase force keys
		{
			ent_animate (me, "walk", my.skill96, anm_cycle);
			my.skill96 += 1 * time_step;
			my.skill96 %= 100;
			wait (1); 
		}
		my.skill42 = 0;
		while(my.skill92 < 100){
			ent_animate (me, "walk", my.skill92, anm_cycle);
			ent_blend("stand", 0, my.skill92); // blend "stand" into "walk"
			my.skill92 += 10 * time_step;
			wait(1);
		}
		while (1){
			ent_animate (me, "stand", my.skill97, anm_cycle);
			my.skill97 += 1 * time_step;
			my.skill97 %= 100;
			wait (1); 
		}
 	}
 }


Posted By: Pappenheimer

Re: Animation problem in my code - 03/20/11 13:19

I guess that you call the function player_animations in a while-loop already, right? Then, you should replace all the whiles with ifs and remove the waits - just to get proper reliable code.

What is odd, too, are the different skills used for counting up the percents for the animations, maybe, there's something mixed up.
Posted By: LawnmowerMan

Re: Animation problem in my code - 03/20/11 16:43

Hi Pappenheimer!

Yes this function is already in whille loop. I'm trying to make the transition between the two animation walk and stand, and I tried to take example from AUM61 but that code is not clear to me, like you say strange is we have different skills for animations? Maybe this example is not good for my case. I need advice how simply make blend betwen two animations. I really stuck with this frown. Here is my animation code:



Code:
function player_animations(){
	my.animation %= 100;
	if (my.animation < 0) { my.animation += 100; }
	
	if (my.state_player == stand) {
		my.animation += 2 * time_step;
		ent_animate (my, "stand", my.animation, ANM_CYCLE);
	} 
	if (my.state_player == run) {
		my.animation += 8.4 * time_step;
		ent_animate (my, "walk", my.animation, ANM_CYCLE); 
	}
}


Posted By: Redeemer

Re: Animation problem in my code - 03/20/11 17:20

Hi,

First of all, this what your original code should look like.

This is your original animation code:
Code:
function player_animations(){
	my.animation %= 100;
	if (my.animation < 0) { my.animation += 100; }
	
	if (my.state_player == stand) {
		my.animation += 2 * time_step;
		ent_animate (my, "stand", my.animation, ANM_CYCLE);
	} 
	if (my.state_player == run) {
		my.animation += 8.4 * time_step;
		ent_animate (my, "walk", my.animation, ANM_CYCLE); 
	}
}


And this is what it should look like:
Code:
function player_animations(){
	if (my.animation > 100) my.animation -= 100;

	if (my.state_player == stand) {
		my.animation += 2 * time_step;
		ent_animate (my, "stand", my.animation, ANM_CYCLE);
	} 
	if (my.state_player == run) {
		my.animation += 8.4 * time_step;
		ent_animate (my, "walk", my.animation, ANM_CYCLE); 
	}
}



To blend between the animations, you need to use ent_blendframe().

Hope that helps. wink
Posted By: Pappenheimer

Re: Animation problem in my code - 03/20/11 17:40

This
my.animation %= 100;
is the the same like this
if (my.animation > 100) my.animation -= 100;

It simply assures that the counter restarts from zero when reaching 100.

I recommend a simple test code where you start the animation and the blending by a key to experiment with it.

The following part of your first code shows the blending in the first while loop where the skill42 is the percentage of the blending of the blended animation, "walk". This value has to be counted up to 100, and then you have to switch to animate the "walk" animation, only, instead of blending it with the "stand" animation.
Code:
while(my.skill92 < 100){
			ent_animate (me, "stand", my.skill92, anm_cycle);
			ent_blend("walk", 0, my.skill42); // blend "wait" into "walk"
			my.skill92 += 10 * time_step;
			wait(1);
		}
		while (1){
			ent_animate (me, "walk", my.skill97, anm_cycle);


Posted By: LawnmowerMan

Re: Animation problem in my code - 03/20/11 19:31

Thank you guys but I will kill myself or I will break my PC mad . I think i going on wrong way. This code from George only play walk animation and whan we press space key animation blend to stand and then stop. I do not see any way how to use this in my code.

Code:
action walk_to_stand(){
	player = me;
	player_camera();
	
	while (key_space == 0)
	{
		ent_animate (me, "walk", my.skill46, anm_cycle);
		my.skill46 += 10 * time_step;
		my.skill46 %= 100;
		wait (1); 
	}
	my.skill42 = 0;
	while(my.skill42 < 100)
	{
		ent_animate (me, "walk", my.skill42, anm_cycle);
		ent_blend("stand", 0, my.skill42);
		my.skill42 += 5 * time_step;
		wait(1);
	}
	while (1)
	{
		ent_animate (me, "stand", my.skill47, anm_cycle);
		my.skill47 += 1 * time_step;
		my.skill47 %= 100;
		wait (1); 
	}
	
}



If there's a better example? This is very difficult for me because I am not an experienced programmer. Whether there is any other function for c-script except ent_blend?
© 2023 lite-C Forums