Spread value to all similar objects in range

This forum is currently in read-only mode.
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • New forums apparently ate my old account, but anyhow... I'm trying to script a simple AI function. Basically, if the enemy sees the player, its alert level changes and it gives chase. I'm trying to make it so that if several enemies are standing next to each other and one of them sees the player, it will also alert all the other enemies within a certain radius.

    I've tried using the Turrent and LOS behaviors with little success. Now, maybe I'm over/under-thinking this and overlooking some kind of useful function, but for some reason I can't seem to figure out how to make this happen. Anyone have some advice?

  • You could easily make a visual solution for this.

    You just create a circular sprite with Your desired radius, which You will make invisible, and create and destroy when necessary. Let's call it RadiusDiscSprite.

    +For Each Enemy

    + If Chase = 1

    SUB+ Trigger Once

    -> Create/Spawn Object (RadiusDiscSprite, At Center of EnemySprite)

    SUB+ Always

    -> Set RadiusDiscSprite.Position to Enemy.Position

    + For Each Enemy

    + Enemy Overlaps RadiusDiscSprite

    + Trigger Once

    • > Set Chase = 1

    + For Each Enemy

    + Whenever Your Event sets Chase back to Chase = 0

    + RadiusDiscSprite: Pick By 'Closest to Enemy' (Or Position = Enemy.Position)

    + Trigger Once

    • > Destroy: RadiusDiscSprite

    I'm sorry, I don't know why indenting in my post doesn't work?

  • Heh, that's actually exactly how I'd handle these things in my "early years" playing around in Multimedia Fusion. I just thought it was messy and was trying to brainstorm a more "elegant" solution which didn't rely on an extra object.

    Then again, it's probably the simplest solution, so cheers <img src="smileys/smiley16.gif" border="0" align="middle" />

  • put the enemy in a family

    we'll call the enemy sprite Badguy, and the family Blue, and your nearbyness radius we'll call Radius:

    Badguy-sees Player

    ---Blue-Pick by comparison-distance(Blue.x,Blue.y,Badguy.x,Badguy.y) less than Radius

    ------Blue chases Player too

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • put the enemy in a family

    we'll call the enemy sprite Badguy, and the family Blue, and your nearbyness radius we'll call Radius:

    Badguy-sees Player

    ---Blue-Pick by comparison-distance(Blue.x,Blue.y,Badguy.x,Badguy.y) less than Radius

    ------Blue chases Player too

    Now that's very elegant. lol

    I was thinking of using distance() too, but I just couldn't get around the problem with the picking, since 'Badguy Sees Player' is already picking.

    But using families is like referencing instances of a new object, so it works. Brilliant.

  • Ooh, lovely, working pretty much as intended now. Thanks lots <img src="smileys/smiley4.gif" border="0" align="middle" />

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