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

0 favourites
  • 4 posts
From the Asset Store
NPC Asset pack
$2.50 USD
50% off
Fantasy RPG Human-NPC assets pack of 15 characters
  • 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?!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

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

  • 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

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