A little help for making a simple AI

Get help using Construct 2

Post » Tue Jul 17, 2012 8:11 pm

Hi .

Fist of all , excuse me for my poor English .

Well , I am making a game . There is a player and 10 zombies . Now I want to make simple AI . When the player gets near to the zombies , they attack him . But I don't know how to make this !

In GM 8.0 , there was a function called : Distance-to-object()
But I couldn't find such a thing in Construct 2.0 .

I tried to use this code , but unfortunately , it didn't work ... :

Event 2 : System : zombie.x <= player.x + 50
          System : Zombie.y <= player.y +50
Action : blah blah blah

Event 1 : System : zombie.x >= player.x + 50
          System : Zombie.y >= player.y +50
Action : blah blah blah

Well , I think this code didn't work because there are more than 1 zombie in the game , just guessing ...

Now , my questions :
1 . Why didn't the code work ?
2 . Is there any other way for doing this ?

Thanks for reading .
B
10
S
2
G
3
Posts: 36
Reputation: 3,315

Post » Tue Jul 17, 2012 8:15 pm

hmm i think you can use distance(player.x,player.y,enemy.x,enemy.y)<...

also there is a trick is that you put a sprite for the range if player overlap that sprite it do blablabla..

about your code i think you should use for each ( i'm not sure )

B
48
S
15
G
6
Posts: 795
Reputation: 12,035

Post » Tue Jul 17, 2012 8:17 pm

Gamer, check out this thread: http://www.scirra.com/FORUM/enemy-movement-and-ai_topic49926.html?KW=

There is a link to an example that might help you.
Wastrel2012-07-17 20:18:43
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Tue Jul 17, 2012 8:42 pm

Thanks for the tips guides , well , I came to the conclusion that the easiest and fastest way is the hidden sprite trick ...
And Wastrel , thanks for the link , I found some other useful information in that thread .
B
10
S
2
G
3
Posts: 36
Reputation: 3,315


Return to How do I....?

Who is online

Users browsing this forum: h1k3 and 19 guests