My main question is basically: What is the algorithm that CPU players use in smash bros to find items like the smash ball? I am trying to make a small ai character that will "look around" and once an item appears it will find it and walk to it. In all smash bros the cpu players are able to find items on the stage when they appear. How do they do this?

  • 3
    There are lots of ways this could be done, from asking the spawning manager for a reference to items it's spawned recently, to using physics or bounds queries to scan for tagged objects in an area of interest, to firing rays to simulate line of sight observation. We'd need to know more about your game and its intended behaviour to recommend the method most appropriate to your needs. – DMGregory Nov 6 at 18:34
  • Thanks for commenting! My game has a character(round, aprox 4x4 pixles) object that is on a 2d plane. At the start of the program "food" items (1 pixel) are generated sudo-randomly spanning the plane. The character currently searches by looping through each pixel in a spiral starting at the character until it hits a food object. This "scanning method" works as long as one edge of the spiral doesn't hit a boundary. So i'm looking for possibly a better method. – Adam Gehring Nov 8 at 22:35
  • Can your method that spawns the food tell the character the coordinates where it put it, or is that "cheating" in your situation? Or, phrased differently, what forms of sensory perception are allowed to your character to gain knowledge about the current game state? – DMGregory Nov 9 at 0:28
  • The idea is to have the "Dot people"(or characters) seem like they are thinking on their own. There's a timer that counts down on the game loop for the character, so after a while, it will get hungry, then it will start looking and go to food once it's found. It's meant to be a simple project in AI so having the "dot person" know where the food is at the time of growing(spawning) would defeat the purpose of the challenge I made for myself. Thanks to your comment and others answers I know understand the answer to the question I wrote, but I realize now that my real question is different. – Adam Gehring Nov 9 at 1:16
  • So the answer to the question above has been answered but big thanks to @DMGregory I now know what my next question should be. – Adam Gehring Nov 9 at 1:21
up vote 2 down vote accepted

On spawn of the object, relevant "listeners" (your NPCs) should be pinged.

Once pinged, the listener can now use the distance from the object, line of sight of the object, the value of the object, the distance of other interested listeners from the object, and other useful variables to develop a weight or a metric that would prioritize any number of available decisions which may result in moving towards the object.

How to find an object

When an object spawns, you could tell all listeners (i.e. NPCs) that the item has spawned and where it has spawned ("where" can be a simple vector point or a reference to a node. More on the latter later). This can be done using an event emitter of some sort, where entities create a listener on some event (e.g. 'onitemspawn') and then act upon it when the event is emitted.

How to move the player towards the item

As soon as the AI agent sees the item, you can program it to move towards the item immediately or when it isn't engaging the player (or whenever really, this is all up to you). When you know where the item is, you can use a pathfinding algorithm like A*. This will find the shortest path to the item quickly.

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.