Efficient way to detect NPC distance?

Get help using Construct 2

Post » Fri Mar 09, 2012 3:14 am

I know dialogue and distance have been discussed, but I wanted to get input on the best way to solve this problem.

Problem: I'd like to be able to interact with 50+ NPCs (individually) whenever I'm within X pixels of a given NPC.

I've see that we can use the distance expression to determine how close an instance is (distance(x1, y1, x2, y2)).

I've also seen someone suggest creating an invisible sprite that is pinned to the NPC and use the "Overlapping" condition.

Are either of these the best way considering the number of NPCs?

edit: I should note, my dialogue is very simple. Each NPC will only have 1 or 2 lines. breravin2012-03-09 03:16:31
B
7
S
1
Posts: 24
Reputation: 935

Post » Fri Mar 09, 2012 3:24 am

The number of NPCs doesn't matter because of how events work.

What's in your interest here is to use a single sprite object to hold all your NPCs (through animationframes of a single animation).
(or families if you own a C2 license)

From the moment you set an event:
System.Compare two values
distance(Player.X,Player.Y,NPC.X,NPC.Y) < The_distance_you_want_to_set
It will apply the actions to every NPCs in the distance. (so your dialog display system)

The overlapping would act the same, but you would must have your player "over" the NPC for the actions to take place, not in an area around it like with distance().Kyatric2012-03-09 03:25:33
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Fri Mar 09, 2012 6:32 am

Ah, great to know. Thanks for the reply!

(Also, I have to say I'm having a blast with this program :))

B
7
S
1
Posts: 24
Reputation: 935


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests