How do I Get npcs to look at me and stay in a area?

Get help using Construct 2

Post » Thu Apr 23, 2015 4:37 pm

Hello everyone, i am having the hardest time trying to get npcs to look toward me when i try to talk to them, i am also have difficulties trying to get npcs to stay in small area so they dont wander off where they shouldnt or worse get stuck

this has to be easy right? i mean the first generation of pokemon and Final fantasy games do this. how hard can it be?!
B
5
S
1
Posts: 88
Reputation: 653

Post » Thu Apr 23, 2015 4:56 pm

If your game is a rpg like pokemon or final fantasy where the camera has an up view you will need at least 4 sprites for each npc. One sprite for them looking up, other looking down and so on.

When the player press the button to trigger the talking all you need to do is add a sub-event (right click or pressing "s"), in this sub events you will have to compare the player position (x,y) to the npc position. If player.x > npc.x then this means the player is at the right side of the npc, so all you need to do is change the npc sprite to that on it is looking right.

But depending on the camera of your game you may want to use the rotate function.
B
17
S
7
Posts: 277
Reputation: 2,514

Post » Thu Apr 23, 2015 5:29 pm

Not so easy ^^

RayKi is right, if you want your npcs look at the player, when you're talking to them, you have to check and compare the position of your player and your npc. Depending on your game, the npc will change animation (4 directions, or 8) or make a rotation (so rotate toward position or set angle toward position). You have to implement a way to know when to trigger the effect and change the npc state.

Pseudo logic :
- when talk key pressed (or any other way)
- check and compare player's position and npcs position to get the nearest one
- pick it and make it change state and animation to start diaglogue

For the npc stay in an area, I assume you already have a behavior or them to wander (you talked about make them stop wandering). There are several ways to do this. You can simply set a zone with an invisible sprite stretched to the desired dimension. When sprite are overlapping that zone, they get wander position inside it, or don't move, if they aren't overlapping that zone, they tend to reach it. For performance reason, you can check overlapping every 0.1 or 0.2 seconds, and not every tick as it's not necessary or this.
B
14
S
4
Posts: 109
Reputation: 1,281

Post » Sat May 02, 2015 1:41 pm

This helped greatly thank you, i had a problem with collisions and the npcs being solid as well but its a minor problem. the Y and X is what got it to work in the end.

Thank you
B
5
S
1
Posts: 88
Reputation: 653


Return to How do I....?

Who is online

Users browsing this forum: leena222, mindragon73, tatogame and 22 guests