Jump to content

How to determine nearby/touching objects for interaction? (e.g. npc)


marvster
 Share

Recommended Posts

Hello together,

 

I'm currently trying to figure out how a player (avatar) on a topdown map may interact with other objects on screen by pressing the action button. And I'm totally locked in a stalemate.

 

Here is my set up:

  1. A player sprite with a body (arcade) which is movable with
    1. a facing direction (up, down, left, right)
    2. a isLocked flag (if he interacts, prevent new interaction)
  2. A group of NPC, each sprite has a body with
    1. an interactionType (dialogue, shop, none)
    2. an optional dialogueList [dialogues [{speaker, spokenText}, ..], ..] to choose from.
    3. an optional shoppingList [{item, price, quantity},...]
  3. A group of (non-physical) Objects with
    1. an interactionType (pickup, door, event)
    2. an optional itemId and itemType (item | weapon | questItem)
    3. an optional eventKey (to call the event)
    4. an optional locationKey (to set the map for changing)
  4. An input key which, when pressed, will check a nearby object, which means an object standing on, or an npc standing next and evaluate the object (interactionType) and make a decision how to work with it (open a dialogue with passing a random set of dialogueLines

While evaluating the object actually comes easy, finding and passing by an object brings the horror.

If tried collides, overlaps and touching, all falls short while it is needed actually walk into an object to trigger a function - if I just stand next a npc and stare at him, none of the events is true. I've read about blocked, but it will just tell me if true or false, but nothing about what is blocking me. And for none-physical objects all four options fall short, as they must not have a body (so the player can stand of it).

Can anyone help me to set my mind back to the right direction?

Link to comment
Share on other sites

Thanks a lot, that was giving me the clue.

 

I've set a key-less child sprite to the player in the same size and set the anchor depending on the direction the player look (0.5 +/- 0.25, 0.5 +/- 0.25), to let it leap a bit of.

With this "sensor-field" I can work with overlap to pass the object for evaluation.

 

Works like a charm. :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...