This question already has an answer here:

I am new to pygame and am creating a small game in which players can push each other to go outside the given arena to score points.
I have a problem in detecting when characters run in to each other. I have a player sprite and enemy sprite to detect collision (pygame.sprite.spritecollide), but to take any action after that is very tricky and am not able to cover all the possible cases. In most of the examples, it is always an immovable object (wall/maze/tanker etc) on the other end and so it is relatively easy to implement. But, with both characters moving, I am unable to calculate exactly and deal with this. Also, my characters just shouldn't run in to each other but can be close enough - because they'll have to be able to push each other.
Can anyone give pointers to implement this.


marked as duplicate by Josh Apr 15 '14 at 15:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


You could model this as a perfectly inelastic collision. That means that the players will keep touching each other after the collision.

Suppose you have two players A and B running at each other at the same speed. A is heavier. So when A and B collide A pushes B backwards and keeps touching B. That seems to me realistic enough when we are talking about characters.

Please see the formulas on this wiki page


Not the answer you're looking for? Browse other questions tagged or ask your own question.