2

Is there a way to dampen a collision in pymunk. I'm trying to simulate space ships and when they collide they shouldn't just bounce apart. Gravity is (0,0). I want to absorb about 90% of an impact basically as if the hull was crumpling under the collision.

One possible thing I thought of is after the post-solve I can read the impulse used to solve the collision and take 90% of that and counteract it making a net solve of 10% but I would need the angular velocity and regular velocity's impulse separate.

I just need to absorb momentum as apposed to no energy being lost in a collision. Its always transferred to the other object.

Edit: Ok so Elasticity helps the bounce but the energy transfer is way too high. The Energy that would transfer is suppose to be absorbed in the crumpling collision. I would still like some to transfer just not much. I'm still thinking about the impulse because that's what actually changes their velocities upon collision. But based on if it's a direct collision or just a clip the amount is very different.

Kaliber64
  • 586
  • 1
  • 5
  • 16

1 Answers1

2

You want to set the shapes' elasticity property. I believe the correct way to do so in pymunk is:

# Replace newElasticity with the elasticity value you want.
# e.g. shape.elasticity = 0.3;
shape.elasticity = newElasticity;

For each collision, the two elasticities are multiplied together, and the product determines how close to an elastic (product = 1.0) or inelastic (product = 0.0) collision the resulting collision will be.

If you want a collision to be 10% of an elastic collision, you'll want to set the elasticities to sqrt(0.1), which is approximately 0.3.

godel9
  • 7,340
  • 1
  • 33
  • 53
  • Ok. So this definitely helps but I'm ganna explain better what it is. – Kaliber64 Nov 21 '13 at 11:37
  • @Kaliber64 Have you tried a lower elasticity? If you go to zero, the objects will stick together after the collision. – godel9 Nov 21 '13 at 12:36
  • It is at zero. It just stops the one that's moving faster from bouncing back after the collision. The other object absorbs a bunch of the firsts momentum. I don't want that much to transfer. – Kaliber64 Nov 22 '13 at 00:11
  • @Kaliber64 Just to double-check... You've tried varying the elasticity between 0.0f and 0.5f, and you can't find a setting that works? How are you setting the masses? – godel9 Nov 22 '13 at 00:28
  • It is working. Elasticity is not doing what it is I want. Basically when a collision happens 90% or so of the energy would simply be deleted. That isn't possible with shape attributes. I'm setting the masses based on area atm. One cubic area is one mass. Mass is currently directly proportional to size/area. – Kaliber64 Nov 22 '13 at 00:43