1

I'm trying to make a game where the player shoots at objects, and when the 'bullet' hits the objects should disappear. Right this works fine, but now I'm trying to make it so the objects only disappear if the bullet gives a certain amount of force / impulse. Anyone know how to do this?

Currently, to get the collisions I'm doing:

collision_handler = space.add_collision_handler(1, 2)
collision_handler.begin = collision_happened
jifeh56745
  • 11
  • 1

2 Answers2

0

You should use a post_solve callback. In that callback you can check if arbiter.total_impulse is bigger than some value. Depending on your logic you might also want to check that arbiter.is_first_contact is true.

viblo
  • 4,159
  • 4
  • 20
  • 28
0

This is from the C based examples, but highly relevant: https://github.com/slembcke/Chipmunk2D/blob/master/demo/ContactGraph.c

A couple notes:

  • The impulse is in units of momentum, length/delta_time gives you the force.
  • For bullets, you probably want the kinetic energy instead. (.total_ke in pymunk)
slembcke
  • 1,359
  • 7
  • 7