Page 1 of 1

how can I change the enemy direction after collision

PostPosted: Tue Dec 14, 2010 7:00 pm
by Orlando911
hey guys, i got confused that, change the enemy direction after he got shot from my player ,

but actually I made change the picture of the enemy after he got shot, but how can I make change his direction (( velocity )) after he get shot,

so the result, when he get shot,

his animation will be changed (( I made it )) and his direction (velocity ).

thank u

Re: how can I change the enemy direction after collision

PostPosted: Tue Dec 14, 2010 8:15 pm
by DarkParadox
Using the code,
Code: Select all
directional_velocity = 0;

Will stop the actor, no matter what direction he is heading in, then you use xvelocity and yvelocity to direct the actor whatever way you want, for example
Code: Select all
xvelocity*=-1;
yvelocity*=-1;

will reverse the direction of the actor (if you didn't set directional_velocity..).
Adding to xvelocity will make the actor go right, subtracting will make it go left. Adding to yvelocity will make the actor go down, and subtracting will make it go up.

Re: how can I change the enemy direction after collision

PostPosted: Tue Dec 14, 2010 8:58 pm
by Orlando911
thank you ,

I tried it , work very well ,

i have another question,

I have player shot ( from left to right )
but when I move player to the left, and his direction change to the left and shot, the shot go to right also,

so how can I make the shot when I go to left when my player walk to the left,

thank you

Re: how can I change the enemy direction after collision

PostPosted: Tue Dec 14, 2010 10:46 pm
by DarkParadox
First, create a variable named "dir" or "direction". (in the script-editor, click variables → add → put 'dir' in the name → click OK).
Then, on keydown → left put:
Code: Select all
dir=-1;

and on keydown → right put:
Code: Select all
dir=1;

Now, the variable always knows what direction you are going in, so on the Create Actor event for Shot, put:
Code: Select all
if(dir == 1)
{
    xvelocity = 7;
}
if(dir == -1)
{
    xvelocity = -7;
}

OR, you could use this shorter version:
Code: Select all
xvelocity = dir*7;

Now your shot should work perfectly, hope this helps!