Collision question

This forum is currently in read-only mode.
From the Asset Store
Particles support animations, collisions, effects and etc.
  • Hi, quick question.

    I'm using the 8direction behavior for the player's character, and I'm working out how to add interactions with other objects. In this case I'm trying to get him to talk to an NPC when they are touching and a key is pressed, and it works almost how I want it to.

    Right now though, the interaction will only occur if the player presses the key and is actively walking into the NPC with the arrow keys. I want the interaction to occur even when the player is stationary next to the NPC and the key is pressed.

    Here is the code in question. Hope that all made sense!

    <img src="http://dl.dropbox.com/u/19777553/forum%20images/blahblahblah.jpg">

  • You will probably need a detector on each side of your player object (at north, south, east and west) and see if any of these objects is overlapping the NPC (i recomend having them as a family) and the button is being pressed

    BTW, a detector is a sprite that keeps a position relative to another object, to detect collisions that can't be detected using common events

  • The problem is the 'on collision' event. That will trigger once, when the two objects meet. So you are having to ram into the NPC constantly. So you could change that event to an 'is Overlapping' event, and have them slightly overlapping each other.

    OR

    What you could do, is set up a private variable toggle. When the characters collide trigger the toggle so that it is locked in conversation mode.

    So it would work something like this,

    On collision between vir and Sprite21 - set PV inConvo to 1

    inConvo is 1? - Set players X and Y movement to 0 so they cannot walk around while talking.

    - Now set the 'text waiting' and key D pressed events in sub events of "inConvo is 1"

    - Talking is finished? - Set PV inConvo to 0

    Hopefully that is enough to get you started.

  • Great! I got it working, thanks

  • For the sake of anyone searching for the solution to the same problem, this is the solution I finally came up with:

    <img src="http://dl.dropbox.com/u/19777553/forum%20images/collision%20example%20b.jpg">

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would like to add another solution if you dont mind.

    Another way to do this is to use "Object is overlapping at offset" condition. So if you are overlapping the sprite at, lets say, 50 pixels away, it would run some actions.

    Yet another would be the expression: "distance(x1,y1,x2,y2)", which calculates the amount of pixels away you are from that object. Its very neat and useful!

    I know your problem is solved, but I want to feel like I'm helping the community.

  • Ah, I didn't understand the object is overlapping at offset" condition. I may experiment with that just for fun

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