how can I change the enemy direction after collision

Non-platform specific questions.

how can I change the enemy direction after collision

Postby Orlando911 » Tue Dec 14, 2010 7:00 pm

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
Orlando911
 
Posts: 84
Joined: Tue Dec 07, 2010 8:18 am
Score: 1 Give a positive score

Re: how can I change the enemy direction after collision

Postby DarkParadox » Tue Dec 14, 2010 8:15 pm

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.
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score

Re: how can I change the enemy direction after collision

Postby Orlando911 » Tue Dec 14, 2010 8:58 pm

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
Orlando911
 
Posts: 84
Joined: Tue Dec 07, 2010 8:18 am
Score: 1 Give a positive score

Re: how can I change the enemy direction after collision

Postby DarkParadox » Tue Dec 14, 2010 10:46 pm

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!
User avatar
DarkParadox
 
Posts: 457
Joined: Mon Jan 08, 2007 11:32 pm
Location: USA, Florida.
Score: 84 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest