Find monster near player

Get help using Construct 2

Post » Thu Dec 15, 2011 12:45 am

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.
B
3
G
1
Posts: 2
Reputation: 529

Post » Thu Dec 15, 2011 2:52 pm

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"
ImageImage
B
25
S
6
G
8
Posts: 773
Reputation: 6,643

Post » Thu Dec 15, 2011 3:33 pm

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
     
B
3
G
1
Posts: 2
Reputation: 529

Post » Thu Dec 15, 2011 10:54 pm

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.
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Fri Dec 16, 2011 10:19 am

@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).
B
33
S
9
G
6
Posts: 709
Reputation: 6,704

Post » Fri Dec 16, 2011 10:25 am

in this cases i always wonder wich method is best, have the system checking constantly for distance or having an extra sprite for collisiondetect..
ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028

Post » Fri Dec 16, 2011 2:31 pm

It's the same, since at each tick the system needs to traverse the object tree to check which we is inside which one...
B
33
S
9
G
6
Posts: 709
Reputation: 6,704

Post » Fri Dec 16, 2011 4:41 pm

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.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Dec 16, 2011 5:01 pm

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




ImageImage
B
61
S
19
G
6
Posts: 809
Reputation: 9,028


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 21 guests