Spread value to all similar objects in range

For questions about using Classic.

Post » Wed Feb 22, 2012 3:17 am

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?
B
2
Posts: 7
Reputation: 264

Post » Wed Feb 22, 2012 5:03 am

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?
                             Shindoh2012-02-22 05:06:58
B
3
G
1
Posts: 70
Reputation: 615

Post » Wed Feb 22, 2012 7:30 am

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
B
2
Posts: 7
Reputation: 264

Post » Wed Feb 22, 2012 10:23 am

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 toolucid2012-02-22 10:25:22
Spriter Dev
B
88
S
21
G
12
Posts: 3,240
Reputation: 16,486

Post » Wed Feb 22, 2012 10:31 am

[QUOTE=lucid] 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[/QUOTE]
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.Shindoh2012-02-22 10:35:59
B
3
G
1
Posts: 70
Reputation: 615

Post » Thu Feb 23, 2012 12:03 am

Ooh, lovely, working pretty much as intended now. Thanks lots
B
2
Posts: 7
Reputation: 264


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests