Login | Register

How to make AI dodge something

August 29, 2007, 09:05 by death-droid
[loading]
-->
This was made for my game Project Revolution which died after 2 days.

So here's the code that I will explain after the code.


if distance_to_object(bulletE)<150 then
motion_add(choose(direction-90,direction+90),2)
else if distance_to_object(bulletE)>150
then speed=0


From top to bottom.

The first bit checks the distance between the bullet at the moment, it's set to lower than 150 pixels.

The next bit is the one that controls the dodging.
It adds a motion that's randomly picked out of two directions, the speed I set it at is 2.

Then it checks if it's further than 150 pixels.
well then it stops the character.


If I haven't explained it good enough just say.

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games