Family issues

0 favourites
  • 7 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • I'm trying to use a family for my npcs to simplify certain events, and I'm having trouble figuring out a way to do this line of code:

    For each NPCS (family)

    • distance(Sprite1 & Sprite2) < 100
    • - (action) - - Set Variable to 1
    • distance(Sprite1 & Sprite2) > or = 100
    • Trigger Once While True
    • - (action) - - Set Variable to 0

    So if there are multiple NPCS on the screen, it's always calculating that the player is > 100 pixels away from at least one of them, so the variable is always set to 0.

    If I switch the family for any sprite, it works fine (for obvious reasons). Is this something you can't do with a family?

  • Shouldn't you check the distance between NPC(family) & Sprite2(player)?

  • Sorry - that's a typo. It is actually distance(Player.X, Player.Y, NPCS.X, NPCS.Y)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Should work, your problem is probably elsewhere. Got .capx you can show?

    for each NPCS

    .. distance(Player.X, Player.Y, NPCS.X, NPCS.Y) < 100

    ... set variable to 1

    .. else

    ... set variable to 0

  • My capx has gotten a little too large to share, unfortunately. I've searched every event sheet for the variable, and this is really the only place it is affected. If I use the same exact lines of code but switch the NPC family (in the distance event) for a single sprite, it works perfectly fine.

  • take a look at this simple capx - dropbox.com/s/mrh0ol7t801ofwt/Distance.capx. if it wouldn't help - show the way how you've done it

  • Thanks for capx, GT88, but it still had the same issue when you add a global variable.

    I've figured another way to do it spawning a sprite on each enemy and setting the variable when the player overlaps it instead of using a distance command. Thanks, guys!

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