Page 1 of 1

Change animation of enemy based on the way your player go

PostPosted: Fri Mar 26, 2010 11:25 pm
by huldra1980
Hi,

I wanted to add an enemy-chase function in my game, and found this code:

angle = direction(x, y, yourhero .x, yourhero .y);
directional_velocity = 10;


And this works perfectly :)

However, I have tried to find a way to change the enemy's animation depending on which way he is chasing my actor. Say, if he is chasing you to the left, it's playing the "running left" animation, but when your player has for example jumped over the enemy and he start chasing you to the right instead, the "running right" animation should display instead.

I haven't found a solution to this, and was hoping anyone here could help me out? :oops:

Re: Change animation of enemy based on the way your player g

PostPosted: Sat Mar 27, 2010 1:32 am
by skydereign
Well, you can use the angle to determine, so where that code goes add this. If you don't already know, // is a way of placing comments in the code, meaning that gameEditor will not read that section. So to make this work you must replace the // ChangeAnimation ones to the actual ChangeAnimation call, and you would want to set the direction to NO_CHANGE.

Code: Select all
if(angle<45)
{
    // ChangeAnimation to east running
}
else if(angle<135)
{
    // ChangeAnimation to north running
}
// And so on...

Re: Change animation of enemy based on the way your player g

PostPosted: Sat Mar 27, 2010 12:05 pm
by huldra1980
Thank you so much! :D

Re: Change animation of enemy based on the way your player g

PostPosted: Sat Apr 03, 2010 3:24 pm
by Hblade
In order to prevent change animation overload, make a temp variable. That way it doesnt reset the animation every frame.for example
Code: Select all
int TEMP
int TEMP2