Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm the one who wrote the original ball bounce code you referenced. If you <a href="http://code.google.com/p/simucal-projects/source/browse/ballbounce/trunk/Ball.java" rel="nofollow noreferrer">download</a> and try out that code, you can see it works fine. </p> <p>The following code is correct (the way you originally had it):</p> <pre><code>// collision impulse float i = (-(1.0f + RESTITUTION_CONSTANT) * vn) / (im1 + im2); CGPoint impulse = ccpMult(mtd, i); </code></pre> <p>This is very common physics code and you can see it nearly exactly implemented like this in the following examples: </p> <ul> <li><a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=531478" rel="nofollow noreferrer">Find collision response of two objects - GameDev</a> </li> <li><a href="http://www.flipcode.com/archives/3D_Pong_Collision_Response.shtml" rel="nofollow noreferrer">3D Pong Collision Response</a> </li> <li><a href="http://www.gamedev.net/community/forums/topic.asp?topic_id=497363" rel="nofollow noreferrer">Another ball to ball collision written in Java</a> </li> </ul> <p>This is correct, and it ~isn't~ creating a CoR over 1.0 like others have suggested. This is calculating the relative impulse vector based off mass and Coefficient of Restitution.</p> <p>Ignoring friction, a simple 1d example is as follows: </p> <pre><code>J = -Vr(1+e) / {1/m1 + 1/m2} </code></pre> <p>Where e is your CoR, Vr is your normalized velocity and J is a scalar value of the impulse velocity.</p> <p>If you plan on doing anything more advanced than this I suggest you use one of the many physics libraries already out there. When I used the code above it was fine for a few balls but when I ramped it up to several hundred it started to choke. I've used the Box2D physics engine and its solver could handle more balls and it is much more accurate.</p> <p>Anyway, I looked over your code and at first glance it looks fine (it is a pretty faithful translation). It is probably a small and subtle error of a wrong value being passed in, or a vector math problem. </p> <p>I don't know anything concerning iPhone development but I would suggest setting a breakpoint at the top of that method and monitoring each steps resulting value and finding where the blow-up is. Ensure that the MTD is calculated correctly, the impact velocities, etc, etc until you see where the large increase is getting introduced.</p> <p>Report back with the values of each step in that method and we'll see what we have.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload