Find monster near player

0 favourites
  • 9 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • Basically just take the beginner tutorial (http://www.scirra.com/tutorials/37/beginners-guide-to-construct-2) and I want to add some monster AI when they are near Player.

    I just can't understand how to make that condition event. There is Distance function but you can only use that in a System Event. That would not be for one individual monster instance. In the Monster event you can just compare instance variables like X or Y. But you can't, that I can see, use the Distance function. So really what I need is the Compare Two values in the Monster Sprite event but that is not an options.

    I would swear this should be easy. If I could just program it would be simple enough but for some reason I am stumped in Construct 2. Also I would love it if the search on the forums was better but everything I hit is for Construct classic and I don't see a way to filter it.

  • In the tutorial's example, look at the event #7

    or if you don't need to compare distance you can just add new condition, choose monster, and find "Pick nearest/furthest"

  • Thanks for the answer. I knew it would be simple enough and a bit stupid for not checking the example file but that was not part of the tutorial. No condition chaining was I guess.

    Here is the answer for those who don't want to look at the file.

    Condition: System -> For each Monster

            System -> distance(Player.X, Player.Y, Monster.X, Monster.Y) < 200

    Action   : ....

    I think I was expecting something more like this

    Condition: Monster -> distance(Player.X, Player.Y, this.X, this.Y) < 200

    Action   : ....

         

    Thanks Again

  • Construct classic has a 'pick by comparison' condition which does that, which hasn't been implemented in C2 yet. You can also set a variable to the distance, and check the variable instead.

  • Jarlax: one quick solution : create a Sprite whith only a circle in it (the color you want, it's not going to be displayed), and a transparent background appart from that color. Pin that centered on your player.

    You can add a condition to check when that circle overlap the plyaer.

    At the beginning of your level, don't forget to put the opacity of your circle at 0 (so it's still there for collision detection, but not displayed on screen).

  • in this cases i always wonder wich method is best, have the system checking constantly for distance or having an extra sprite for collisiondetect..

  • It's the same, since at each tick the system needs to traverse the object tree to check which we is inside which one...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The result is not the same.

    If you check the distance you basically discard the size of the sprite.

    If you use a sprite for collision/overlapp detect you don't care where the hotspot is.

    I guess the first one is better for small elements and the second one should be use for bigger ones.

  • by collision , i would think that the system instantly knows its that object, but Pode maybe right that it still has to traverse, you do have to add the positionsetting for the detectorsprite

    as for the small vs bigger elements, does it matters? i dont think it takes more calculation for bigger or smaller (invisible) objects if you use the same sprite but bigger

    but hey probably doesnt matter that much anyway, maybe on mobile

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