// Applies an impulse based on a collision private void CollisionResponse(PhysicsObject pm, PhysicsBox b) { // Find the normalized relative velocity Vector3 relVel = pm.Velocity; Vector3 norm = pm.Position - b.Position; float nVel = Vector3.Dot(relVel, norm); // Set velocity to halt movement pm.Velocity = Vector3.zero; // Restitution (bouncyness) float e = 0.9f; // Calculate impulse float j = -(1 + e) * nVel; j /= (pm.mass + b.mass); Vector3 impulse = j * norm; pm.AddImpulse(impulse); }