0 Favourites

Efficient way to detect NPC distance?

  • 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.

  • 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().

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Ah, great to know. Thanks for the reply!

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

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