Page 1 of 2

GRADUAL ANIMATION

PostPosted: Tue Nov 20, 2012 2:45 pm
by sonicforvergame
HI everybody
is there any way so that I can start with a walking animation to go to a running animation than go to a verry fast animation and taking in account the speed of the player ???

if you want something more easy how can i make a sonic animation
slow-->fast-->verry fast
without missing the speed ???

Re: GRADUAL ANIMATION

PostPosted: Tue Nov 20, 2012 7:03 pm
by Soullem
somebody could probably tell you a more seamless way, but here I go assuming you are doing this for a sonic platformer
First create three variables speed and TimeMove and TimeAnim
on key down right
Code: Select all
TimeMove+=1;
if (TimeAnim<0)
{TimeAnim=0}
TimeAnim+=1;


and on left
Code: Select all
TimeMove-=1;
if (TimeAnim>0)
{TimeAnim=0}
TimeAnim-=1;


then in draw actor add something along the lines of

Code: Select all
if (TimeMove == 0)
{
    speed=0;
}
if (TimeMove <= 10 && TimeMove >0)
{
    speed=2;
}
if (TimeMove <= 20 && TimeMove >10)
{
    speed=4;
}
if ( TimeMove >20)
{
    speed=8;
}
if (TimeMove <= 0 && TimeMove >-10)
{
    speed=-2;
}
if (TimeMove <= -10 && TimeMove >-20)
{
    speed=-4;
}
if ( TimeMove >-20)
{
    speed=-8;
}

xvelocity=speed


then do the same for the animation using Time Anim and ChangeAnimation. If you need any help feel free to ask.
also I would wait to use this and see if someone makes something better.

Re: GRADUAL ANIMATION

PostPosted: Wed Nov 21, 2012 1:20 pm
by sonicforvergame
Well i didn't understand all
for example the script you have put now what is it for THE SPEED ??
if yes what dose it do

Re: GRADUAL ANIMATION

PostPosted: Wed Nov 21, 2012 8:49 pm
by Soullem
So the variable TimeMove counts for how long you hold down the left and right arrow keys.
the IF statements set a range for the speed value to change.

Then you set the xvelocity(how fast moving left and right) to equal that speed value.

Heres my code with comments

on key down right

Code: Select all
TimeMove+=2; //add to time holding down right key
if (TimeAnim<0) //if you were moving left set TimeAnim to 0, so he turns to the right right away
{TimeAnim=0;} 
TimeAnim+=2;  //add one to time trying to run right


on key down right
Code: Select all
TimeMove-=2;  //add to time holding down left key, so he turns left right away
if (TimeAnim>0)
{TimeAnim=0;}
TimeAnim-=2;


Draw Actor
Code: Select all
if (TimeMove == 0) //if not pressing key and slowed down
{
    speed=0;  //set speed to 0
}
if (TimeMove <= 10 && TimeMove >0)  //if pressing to the right for 1-10 frames
{
    speed=2; //set speed to 2
}
if (TimeMove <= 20 && TimeMove >10)  //if pressing to the right for 11-20 frames
{
    speed=4;  //set speed to 4
}
if ( TimeMove >20)  // if pressing for more than 20 frames
{
    speed=8; //set speed to eight
}
if (TimeMove <= 0 && TimeMove >-10)  // if holding left for 1-10 frames
{
    speed=-2; //set speed to negative 2
}
if (TimeMove <= -10 && TimeMove >-20) //you get the pattern...
{
    speed=-4;
}
if ( TimeMove <-20)
{
    speed=-8;
}
xvelocity=speed;  // set the xvelocity to be the value of our variable speed
//  xvelocity is how fast the player is moving left and right.
if (TimeMove>0) //check if moving right
{TimeMove-=1; //this decreases the value of TimeMove once a frame so Sonic slows down
}
if (TimeMove<0) //check if moving left
{TimeMove+=1; //this increases the value of TimeMove towards 0 once a frame so Sonic slows down
}

ill make a demo soon...

Re: GRADUAL ANIMATION

PostPosted: Wed Nov 21, 2012 9:05 pm
by Soullem
Here it is. You can copy the parameters and change TimeMove into TimeAnim for the animation. If you dont understand how to just ask :D

Re: GRADUAL ANIMATION

PostPosted: Thu Nov 22, 2012 2:54 pm
by sonicforvergame
Thanks soullem that was NICE you really help me here
i will make sure to show you my sonic game when i finish it
thanks again

Re: GRADUAL ANIMATION

PostPosted: Thu Nov 22, 2012 6:32 pm
by Soullem
No problem, I'm happy to help.

Also you could add more times where it changes speed so its smoother, this is more of a template, im pretty sure if you play around with values you could get it smoother

Re: GRADUAL ANIMATION

PostPosted: Sun Jan 13, 2013 1:12 pm
by Bee-Ant
Maybe I'm late here, but it's OK.
Let me share my method.
Probably this one for other people who come to check this thread :)

PREPARATION

Give the player 3 animations, same animation but with different fps. For example:
- PlayerRunLeft1 ~ 10 fps
- PlayerRunLeft2 ~ 20 fps
- PlayerRunLeft3 ~ 30 fps
- PlayerRunRight1 ~ 10 fps
- PlayerRunRight2 ~ 20 fps
- PlayerRunRight3 ~ 30 fps

Make 3 integer variables via script editor:
- speed
- run
- direct


CODE

Player > KeyDown > Left > ScriptEditor:
Code: Select all
run〓1;
speed++;
x-〓speed/5;
direct〓0;


Player > KeyDown > Right > ScriptEditor:
Code: Select all
run〓1;
speed++;
x+〓speed/5;
direct〓1;


Player > KeyUp > Any Key > ScriptEditor:
Code: Select all
run〓0;


Player > DrawActor > ScriptEditor:
Code: Select all
char str[32];
char directText[3][8]〓{"Left","Right"};
speed〓max(0,min(speed,59)); //limit the speed value
if(run〓〓0)
{
    speed-〓5;
}
sprintf(str,"PlayerRun%s%i",directText[direct],speed/20+1); //get the animation name
ChangeAnimation("Event Actor", str, NO_CHANGE); //change the player animation

if(speed<〓0&&direct〓〓0)ChangeAnimation("Event Actor", "PlayerStopLeft", NO_CHANGE);

if(speed<〓0&&direct〓〓1)ChangeAnimation("Event Actor", "PlayerStopRight", NO_CHANGE);


That's all :)
Any question?

Re: GRADUAL ANIMATION

PostPosted: Sun Jan 13, 2013 1:31 pm
by sonicforvergame
YOU ARE AWSOME at acripting that is all and really good i am sure it's going to work anyway i will tell you if it did work or not

Re: GRADUAL ANIMATION

PostPosted: Sun Jan 13, 2013 1:54 pm
by sonicforvergame
sorry but it didn't quite work ther are some problems i will give you my demo soon so you can see what is wrong is it Bee-Ant

Re: GRADUAL ANIMATION

PostPosted: Sun Jan 13, 2013 2:29 pm
by Bee-Ant
Another method with simpler code but a bit more complicated preparation:

PREPARATION

Give the player 3 run animations, same animation but with different fps. For example:
- PlayerRunLeft1 ~ 10 fps
- PlayerRunLeft2 ~ 20 fps
- PlayerRunLeft3 ~ 30 fps
- PlayerRunRight1 ~ 10 fps
- PlayerRunRight2 ~ 20 fps
- PlayerRunRight3 ~ 30 fps
And stop animation:
- PlayerStopLeft1 ~ 10 fps
- PlayerStopRight1 ~ 10fps

Make 4 integer variables via script editor:
- speed
- run
- direct
- stop

CODE

Player > KeyDown > Left > ScriptEditor:
Code: Select all
run〓1;
stop〓0;
speed++;
direct〓-1;


Player > KeyDown > Right > ScriptEditor:
Code: Select all
run〓1;
stop〓0;
speed++;
direct〓1;


Player > KeyUp > Any Key > ScriptEditor:
Code: Select all
run〓0;


Player > DrawActor > ScriptEditor:
Code: Select all
char str[32];
char directText[3][8]〓{"Left","None","Right"};
char stateText[2][8]〓{"Run","Stop"};
speed-〓(run〓〓0)*5; //if you release the button, reduce the speed bit by bit
speed〓max(0,min(speed,59)); //limit the speed value
x+〓speed/5*(stop〓〓0)*direct; //x movement decided by speed, stop and direct
sprintf(str,"Player%s%s%i",stateText[stop],directText[direct+1],speed/20+1); //get the animation name
ChangeAnimation("Event Actor", str, NO_CHANGE); //change the player animation
if(speed<〓0&&run〓〓0)stop〓1;

Re: GRADUAL ANIMATION

PostPosted: Sun Jan 13, 2013 2:33 pm
by Bee-Ant
sonicforvergame wrote:sorry but it didn't quite work ther are some problems i will give you my demo soon so you can see what is wrong is it Bee-Ant

Did you just copy-paste my code?
So sorry but I'm mobile now, and it seems "〓" character here is not the same as "〓" character in PC. So I suggest you to replace it :o

Re: GRADUAL ANIMATION

PostPosted: Sun Jan 13, 2013 4:26 pm
by sonicforvergame
i did but i think i made a mistake with the preperation i will try the new code

Re: GRADUAL ANIMATION

PostPosted: Mon Jan 14, 2013 1:25 am
by Bee-Ant
I did try it, and it worked just perfectly. Except for the sudden turn brake... will think about it later :)
I don't know what's wrong with how did you do it, but here's the demo I make:

Re: GRADUAL ANIMATION

PostPosted: Mon Jan 14, 2013 1:32 am
by GEuser
Just checked the download. Seems to work fine for me Bee-ant.