PhysicsCollisionListener - need some help

Hello everyone,



I’m having some trouble with collision detection and I’m hoping for some help.





I want to make the player be able to talk to an NPC with whom he collides by pressing a button.



My class implements PhysicsCollisionListener and I check for the collsion in the collision() method. When the collision is detected, a flag is set to true, enabling the player to initiate the talking when the correct button is pressed. This flag should be set to false, when the collsion no longer occurs.



However, I don’t know where to set the flag to false, as collision() is only called when a collision is detected. If I set it in the update loop, it (obviously) sometimes makes the player unable to talk to the NPC even though he is colliding with him.



So how can I get this to work? Or is there something I’m missing here?

Thanks in advance, guys.

Collisions happen in physics ticks, use a PhysicsTickListener.

I have already looked at PhysicsTickListener, but I can’t figure out how it will help me. Could you please give me some tips?

Basically all I need is a way to find out if a collsion is not happening…

If the collision flag is set, you can just check in the update loop if you are further than a specific distance and then set the collision to false.

I don’t know what more to say… Physics calculations only happen in a physics tick, so if you got a collision report within one tick and the next tick there was none then theres no collision detected anymore. Just use the tick callback like you would have used update() and then do everything as you did.

The solution Dodikles proposed works very well! Problem solved!



I’m still confused about the PhysicsTickListener though and how it works together with the collision() method. I just… can’t seem to understand it at all. I suspect that I’ll need it later on in my game, so if you have the time to spare, could you please give me a simple example, normen?





Thank you very much for your time. I really appreciate it!

Not really, no. Just each time physics is stepped this method is called, it can be once every other frame or even multiple times in one frame if the framerate is below the physics space framerate. The BombControl example uses it.