Interacting with NPC while facing him

This forum is currently in read-only mode.
From the Asset Store
Fantasy RPG Human-NPC assets pack of 15 characters
  • I've been trying to figure out what I could possibly be doing wrong here for a very long time so I'm just gonna go ahead and ask...

    My problem is interacting with NPCs - everything works fine except for the events that are supposed to determine if the player's sprite is facing the NPC. Here is essentially what I have...

    After picking the right NPC object that's closest to the player, I have a long list of events that are supposed to detect the player's position compared to the NPC's. In other words...

    <img src="https://dl.dropboxusercontent.com/u/29310757/thing.PNG" border="0" />

    So, if the player's ("AlienBox") X position AND Y position is higher than the NPC's, the player should be somewhere along the bottom right corner of the NPC. Then, if the angle of the player is appropriate, a value for "Facing" is set to 1.

    The issue I'm having isn't that this doesn't work - it's that when I add events for each possible position (three more, for the other three corners), only the first two that I've listed do anything. So, if I have the events for bottom right and bottom left up higher on the event sheet than top right and top left, only bottom right and bottom left will function. I've mixed and matched all 4 events, and regardless of what they say, only the first two I've listed work.

    I'm really stumped by this one... no clue what could possibly be going wrong. The only other way I can think to test positioning would be to add a detector object, but I would really prefer not to do that. Anyone have any idea what might be going on here?

  • NEVERMIND. That was stupid - the Else's are conflicting, duh.

    But I guess I'm still not entirely sure what to do here for this. I can't figure out a way to set "Facing" back to 0.

    I'm sorry this problem is going to end up being really specific... I'll try to go into any more detail if need be, but hopefully I'll figure something out.

    EDIT: yaaaay I figured it out! Or, at least, I got something working. So... I guess nevermind completely then! I'll post if I run into some other snag.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Another way to do it is to have an invisible sprite that is always in front of your player. If invisible sprite overlaps NPC and action key is hit, trigger event.

  • That's something I considered, but I've been trying to avoid using trigger objects like that, mostly because I think it'll be good practice for me to come up with other ways, haha.

    That might actually be more efficient than the way I'm doing it now, though. Oh well. <img src="smileys/smiley17.gif" border="0" align="middle" />

  • You might not need to keep track of an invisible sprite.

    Try the overlapping by offset condition for your player.

    For x and y use cos(Player.Angle)*distance and sin(Player.Angle)*distance.

    For distance you just do however wide your character is i guess.

    I'm thinking of doing the same thing in my game, and I was going to try it out today.

    Good luck, I'll report back if it works in my game.

  • Or even use the line of sight behaviour as a range test.

  • You might not need to keep track of an invisible sprite.

    Try the overlapping by offset condition for your player.

    For x and y use cos(Player.Angle)*distance and sin(Player.Angle)*distance.

    For distance you just do however wide your character is i guess.

    I'm thinking of doing the same thing in my game, and I was going to try it out today.

    Good luck, I'll report back if it works in my game.

    Seems like an interesting solution. What I ended up doing was putting a "trigger once" on all of the else's - so they conflict with each other on one tick, but that's not really enough to make any significant difference.

    The line of sight behavior sounds interesting, too, I've never tried it. If my system for this starts giving me trouble, I'll definitely look into it.

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