PhysicsTickListener Interface Question (sorry if dupe)

Thought I posted this before…but didnt see it pop…if so sorry for the dupe post…



Hi folks I’m trying to figure out if I ‘understand’ this interface correctly…and trying to get some more direction before going to far down this path…if its wrong.



My Use Case:

Ball rolling around table, and when it hits an object I need to increment a score.



My Conclusion:

While I can use the PhysicsCollisionListener Interface, this does not give me the ability to increment the score only once when the collision occurs, since the collision method is called constantly while in a collision state. As such, the PhysicsTickListener, will result in at most 1 call to the preTick method just before collision…(correct?) Also from what I can tell, in order to use the PhysicsTickListener I must have a PhysicsGhostObject (I guess I would have this setup to mimic the size of the actual ball).



Then in the method: prePhysicsTick

I would be able to call ghostObject.getOverlappingObjects() (and iterating through this I should find the object(s) collided with, and apply the appropriate score).



now…at some point in time I need to apply forces (so the ball bounces off correctly); can use the PhysicsCollisionListener at the same time for this? or must I apply the forces manually via the prePhysicsTick method?



Also given the above use case, I take it in the method: physicsTick(…) I would not need to do anything…since the prePhsyicsTick is used for both score and/or forces? correct?



thanx

noob trying to muddle my why through this.

No, all wrong ^^ PhysicsTickListener is only a way to listen to actual physics space updates (which are not necessarily happening each frame) and it gets called continuously each physics frame as soon as you add it to the physics space.

lol, well I’m glad I asked before spending too much time going down the wrong road :slight_smile:



Anyways, I think I just figured out what I needed in the shower…



Using PhysicsCollisionListener, the collision method is called while the collision is taking effect.



However based on that the velocity of the ball will change, in particular the direction. As such…if I ‘track’ the direction of the ball, then when I see a collision occur, I can test the direction of the ball, if it has changed (direction) from the collided object (I logically can conclude the collision is ‘ending’) and bump up the score, if the method get invoked again, since the collision has not actually ended…the score will remain unchange…as the direction of the ball should not have changed (unless of course there was another object to collide with).



I’m going to try that out, and see where it gets me :slight_smile:

Its called each physics tick actually, as long as the two objects touch. so to make it 100% working you can just check if a collision was reported in postTick()

1 Like