"Pick closest" not working.

For questions about using Classic.

Post » Tue Oct 16, 2012 6:02 pm

I'm planning to make a game of evolution based on natural selection. To test some things, I created a test project and created some basic forms of AI.

In the project, I created a sprite called 'npc' which has a variable called 'food' that, in turn, is decremented by 1 over the frames. I created also another sprite called 'food' that serves as food, as its name suggests.

The variable 'food' of the sprite 'npc' is initialized with 200 and, when it is less than or equal to 50, the NPC should go after food. For this functionality, I applied the behavior 'RTS' to make things easier. For a more realistic behavior, I made this food (for which the npc should seek) to be as close as possible. For this, I tried to use the "Pick closest", but somehow is not working right.

The problem is that when the npcs "get hungry", they always go after the same food, i.e., they do not go after the food closer to them.

(I can freely create npcs and foods by pressing the left or right mouse buttons.)

Here is my event sheet:

+ System: Start of layout
   -> npc: Destroy
   -> food: Destroy

+ MouseKeyboard: On Left mouse button Clicked
   -> System: Create object npc on layer 1 at (MouseX, MouseY)

+ MouseKeyboard: On Right mouse button Clicked
   -> System: Create object food on layer 1 at (MouseX, MouseY)

+ System: Always (every tick)
   -> npc: Subtract 1 from 'food'

+ npc: Value 'food' Less or equal 50
   + food: Pick closest to: npc.X, npc.Y
      -> npc: Add waypoint at food
B
2
Posts: 6
Reputation: 262

Post » Tue Oct 16, 2012 9:36 pm

There's two things you could try out on your last event that compares npc's 'food' <= 50. Try adding For each 'npc' for the event, that way you can make sure to compare each one properly or adding Pick by comparison where you pick 'npc' with comparison 'food' <= 50.

So the last event becomes

+ System: For each npc
+ npc: Value 'food' Less or equal 50
   + food: Pick closest to: npc.X, npc.Y
      -> npc: Add waypoint at food

or

+ npc: Pick by 'food' Lower or equal 50
   + food: Pick closest to: npc.X, npc.Y
      -> npc: Add waypoint at food
B
11
S
2
G
3
Posts: 100
Reputation: 2,150

Post » Tue Oct 16, 2012 9:42 pm

It worked perfectly. Thank you a lot!
B
2
Posts: 6
Reputation: 262


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests