"Pick closest" not working.

This forum is currently in read-only mode.
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • 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

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It worked perfectly. Thank you a lot!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)