I am going to take a hit on this without trying it, so I cannot guarantee that it is accurate. Also, this is pseudo code.
We need to know the point of collision between the spheres. If you expect each frame to detect a collision, your spheres are likely to be partially interpenetrating, so the first thing I would like to do is push them out of each other. To do this, you need to know how far each one can go.
Vector3 BtoA = (SphereA.center - SphereB.center); Vector3 AtoB = (SphereB.center - SphereA.center); float currentDistance = AtoB.length(); float minimumDistance = SphereA.radius + SphereB.radius;
If you want to be more precise with your refusal, you should be able to figure out, based on the depth of penetration of the spheres, how much time has passed since they would have collided if you had not used the framework-based application. This should allow you to calculate how much they should be far now that they have bounced apart. If you calculate this time, you can take the speed of the sphere, which we calculated above, and change the position of the spheres by this amount of time.
As I said earlier, I have not tested this code at all, so it may not work at all, but at least it may be a good starting point for you or it may be close to functional. Hope this helps. Good luck.
source share