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