Search Unity

Colission problem? Talk to NPC / Do action - Javascript

Discussion in '2D' started by TehChriis, Sep 15, 2014.

  1. TehChriis

    TehChriis

    Joined:
    Feb 26, 2014
    Posts:
    16
    So I'm making a mini 'game' demo to try some game ideas out and get the code working. I'm trying to figure a way out for this, but I think there should be a way easier way to do this rather than the ways I'm thinking of.

    The game is like this:
    You just have a 2d character, you can walk left and right and jump. I want it so that you just need one (or maybe a few more) buttons to do everything. You can walk up to a npc and press 'S' to talk to him, and ofcourse 'S' to continue. then he sets you off on a fishing quest or whatever, and then you can press 'S' to fish.

    something like this, (I made a basic drawing in paint..):


    I think it shouldn't be too hard, an 'if(player.x/y = fishingspot == true) && "S" is pressed{start fishing}
    I know that's the worst code out there, but something like that right?

    the problem I'm having right now is a collison detection, how can I make it so if the player is standing close to the npc, he can talk to him? right now I can't even get a basic colission working between a player and a npc so that it debug.logs it.

    Also I'm wondering. how would I make text appear above the npc? would the best way to use a GUI system?

    Thank you in advance!
     
  2. TehChriis

    TehChriis

    Joined:
    Feb 26, 2014
    Posts:
    16
    Figured it out, nevermind.
     
  3. SpacemanBoots

    SpacemanBoots

    Joined:
    Nov 27, 2012
    Posts:
    32
    It's nice to share your solution so when someone else is having the same problem he won't just find this empty thread.
    You might also receive some feedback.
     
  4. Limeoats

    Limeoats

    Joined:
    Aug 6, 2014
    Posts:
    104
    In terms of interacting with the NPC when you are near it, simply extend a Box Collider 2D to the sides of the NPC, and make it non-collideable with a layer mask.