Independent NPCs facing player

0 favourites
  • 4 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • I'm not sure how to put this properly. I'm a complete newbie when it comes to logic statements and programming in general, so I'll try to be as clear as I possibly can.

    Here is what I want to do:

    I want the NPCs for this instance of my game to always face the player when the player is within a set range, and set its layering so that it is in front of the player when the player "goes behind" the NPC, and behind the player when the player "goes in front" of the NPC. I would like them all to act independently, but use the same code and come from the same object, so I don't have to create 100 different NPC's that basically do the same thing.

    Essentially, what I want is for the player to approach an NPC and for that NPC to face that player and layer itself accordingly, without the others changing their own values that are not within range.

    What I have now:

    I can get ONE NPC to track the player based on his X and Y in relation to him, and layer itself accordingly.

    If I add another, it just flat out breaks. I have no idea how to make them independent of each other.

    <img src="https://dl.dropbox.com/u/33658489/blargh.jpg" border="0" />

    This is what I have as far as scripting goes.

    <img src="https://dl.dropbox.com/u/33658489/blargh2.jpg" border="0" />

    This is what the layout looks like. I want these guys both to face the player independently of one another.

    Any help would be appreciated. Thank you.

  • From what I can see, you're testing if the player is to the right or left of the shadow. You need to test using the npc.. you'll get proper picking then.

    + for each npc01

    + if npc01.x < player.x

    -   npc01 set animation to right

    + if npc01.x > player.x

    -   npc01 set animation to left

  • You will probably also want to pop the player in front of the NPC based on the Y position relationship to each other.

    there's a plugin for just such a thing.

    scirra.com/forum/plugin-isometric-z-ordering-based-on-y_topic46247.html

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • From what I can see, you're testing if the player is to the right or left of the shadow. You need to test using the npc.. you'll get proper picking then.

    + for each npc01

    + if npc01.x < player.x

    -   npc01 set animation to right

    + if npc01.x > player.x

    -   npc01 set animation to left

    You will probably also want to pop the player in front of the NPC based on the Y position relationship to each other.

    there's a plugin for just such a thing.

    http://www.scirra.com/forum/plugin-isometric-z-ordering-based-on-y_topic46247.html

    Wow! Really helpful posts. I'll be sure to implement these and see how they go. Thanks, based community ! Very appreciated! <img src="smileys/smiley36.gif" border="0" align="middle" />

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