Change animation of enemy based on the way your player go

Non-platform specific questions.

Change animation of enemy based on the way your player go

Postby huldra1980 » Fri Mar 26, 2010 11:25 pm

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:
huldra1980
 
Posts: 7
Joined: Sat Jan 23, 2010 4:27 pm
Score: 0 Give a positive score

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

Postby skydereign » Sat Mar 27, 2010 1:32 am

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...
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

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

Postby huldra1980 » Sat Mar 27, 2010 12:05 pm

Thank you so much! :D
huldra1980
 
Posts: 7
Joined: Sat Jan 23, 2010 4:27 pm
Score: 0 Give a positive score

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

Postby Hblade » Sat Apr 03, 2010 3:24 pm

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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron