Collision question

For questions about using Classic.

Post » Fri Feb 25, 2011 3:37 am

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!

B
3
G
1
Posts: 23
Reputation: 521

Post » Fri Feb 25, 2011 5:02 am

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
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Fri Feb 25, 2011 5:28 am

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.
B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Fri Feb 25, 2011 6:09 am

Great! I got it working, thanks
B
3
G
1
Posts: 23
Reputation: 521

Post » Sat Feb 26, 2011 3:51 am

For the sake of anyone searching for the solution to the same problem, this is the solution I finally came up with:
B
3
G
1
Posts: 23
Reputation: 521

Post » Sat Feb 26, 2011 6:49 am

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. :lol:
B
26
S
7
G
5
Posts: 202
Reputation: 5,235

Post » Sat Feb 26, 2011 6:00 pm

Ah, I didn't understand the object is overlapping at offset" condition. I may experiment with that just for fun
B
3
G
1
Posts: 23
Reputation: 521


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests