Independent NPCs facing player

Get help using Construct 2

Post » Thu Jan 03, 2013 2:06 am

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.


This is what I have as far as scripting goes.


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.
B
2
Posts: 3
Reputation: 406

Post » Thu Jan 03, 2013 6:54 pm

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
B
15
S
5
G
7
Posts: 877
Reputation: 5,650

Post » Thu Jan 03, 2013 9:01 pm

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

B
50
S
21
G
8
Posts: 844
Reputation: 10,299

Post » Fri Jan 04, 2013 3:04 am

[QUOTE=procrastinator] 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
[/QUOTE]
[QUOTE=justifun] 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

[/QUOTE]

Wow! Really helpful posts. I'll be sure to implement these and see how they go. Thanks, based community ! Very appreciated!
B
2
Posts: 3
Reputation: 406


Return to How do I....?

Who is online

Users browsing this forum: Artpunk, Axiomaltd, MACPK, nicklowkcmagic, OddConfection, radbrothers and 24 guests