We get it. We use ad blockers too. But GameDev.net displays them so we can continue to be a great platform for you.
Please whitelist GameDev.net and our advertisers.
Also consider a GDNet+ Pro subscription to remove all ads from GameDev.net.
Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
Posted 10 June 2008 - 01:17 PM
Posted 10 June 2008 - 09:30 PM
Vector delta = (pos1 - pos2); // delta vector
float d = delta.length(); // delta vector length
if(d > (r1 + r2)) return false; // no intersection
mtd = delta * ((r1 + r2)-d)/d; // the minimum translation distance vector
pos1 += mtd * 0.5f;
pos2 -= mtd * 0.5f;
Vector n = mtd / mtd.length(); // normal of collision
Vector v = (vel1 - vel2); // relative velocity
float vn = v.dotProduct(n); // impact speed
if(vn > 0.0f) return false; // ball already moving away from each other. stop response.
float cor = 0.8f; // coefficient of restitution (range [0, 1].
float i = -((1.0 * cor) * vn) / 2.0f; // impulse quantity
Vector impulse = i * n; // impulse vector
vel1 += impulse; // apply impulse to change ball 1 monentum
vel2 -= impulse; // apply impulse to change ball 2 monentum
Posted 10 June 2008 - 10:12 PM
Posted 11 June 2008 - 07:17 AM
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.
GameDev.net™, the GameDev.net logo, and GDNet™ are trademarks of GameDev.net, LLC.