## Chipmunk and perfect bounce...

Nibbie
Posts: 3
Joined: 2009.03
Post: #1
hi people , i just want to create a perfect bounce using Chipmunk library;

I create a little wheel that collides againt a rect with INFINITY mass and e = 1.0f (elasticity parameter), i want the bounce to be perfect ; i mean that the wheel should come back after the impact with the same velocity in module but it collides it stops suddenly !!!

Where i'm wrong? what should i do to create a perfect bounce?
Moderator
Posts: 684
Joined: 2002.11
Post: #2
I had this issue a while back. You need to set elasticIterations to 5 on the space, if I remember correctly. I would give you more if I were inclined to look it up, but this should be enough to aid a quick Googling.

My web site - Games, music, Python stuff
Moderator
Posts: 484
Joined: 2008.04
Post: #3
Make sure that the wheel and the rect both have an elasticity of 1.0. I think Chipmunk multiplies them together.

From: http://files.slembcke.net/chipmunk/chipmunk-docs.html

"The amount of elasticity applied during a collision is determined by multiplying the elasticity of both shapes together. "

Howling Moon Software - CrayonBall for Mac and iPhone, Contract Game Dev Work
Nibbie
Posts: 3
Joined: 2009.03
Post: #4
diordna Wrote:I had this issue a while back. You need to set elasticIterations to 5 on the space, if I remember correctly. I would give you more if I were inclined to look it up, but this should be enough to aid a quick Googling.

thank you so much ... i used space elasticIteration and it worked perfectly.

Just an other question when my wheel runs trought the space it should reduce its speed little by little. how can i reproduce this effect?
Moderator
Posts: 684
Joined: 2002.11
Post: #5
I think bodies have an angularVelocity attribute or something. I don't remember the exact name. You can multiply it by a constant less than 1 (like 0.9) every frame

I can't remember how to do time-based drag, so someone else should chime in on this.

My web site - Games, music, Python stuff
Moderator
Posts: 484
Joined: 2008.04
Post: #6
Yeah, angular velocity, or w. Multiplying it by .9 or similar every frame works well.

Howling Moon Software - CrayonBall for Mac and iPhone, Contract Game Dev Work
Apprentice
Posts: 13
Joined: 2009.03
Post: #7
yeah, something like that:

Code:
```cpFloat angularDamping = 0.05; body->w *= (1.0-angularDamping);```
Nibbie
Posts: 3
Joined: 2009.03
Post: #8
sthaqu Wrote:yeah, something like that:

Code:
```cpFloat angularDamping = 0.05; body->w *= (1.0-angularDamping);```

Where i put this code? tnx
Member
Posts: 89
Joined: 2005.06
Post: #9
Couldn't he just apply damping to his entire space?

Code:
```space = cpSpaceNew(); space->damping = 0.01;```

Well since everyone else is doing it:
Twilight Coders