4 ms·
The problem with that solution is it's slow and not that accurate. In an actual game you probably want something like: safedist = (obj1.saferadius + obj2.sa
by Retric 16y ago
The problem with that solution is it's slow and not that accurate.
In an actual game you probably want something like:
safedist = (obj1.saferadius + obj2.saferadius)
if (abs(ob1.x - box2.x) < safedist)
if (abs(ob1.y - box2.y) < safedist)
if (faster_test(ob1,ob2)//aproximates square roots
if (full_test(ob1,ob2))//slow, but avoids bugs
{do stuff...}
- thebooktocome 16y agoThere's no need to take square roots. sqrt(x) is monotone increasing, so comparing squared-distances is equivalent to comparing distances.
- Retric 16y agoIf all you want is distance between points (x1-x2)^2+(y1-y2)^2+(z1-z2)^2 = dist^2 works. However, in games you frequently want to check the intersection of lines, or spheres with plains, cubes etc. And for those equations you often have to deal with the inverse square root function. PS: Anyway, my point was more abut the process. First you try A, which culls 90% of your objects, then you try B which culls 95% of the objects then you do the full and actuate solution if you have time. http://en.wikipedia.org/wiki/Ragdoll_physics http://en.wikipedia.org/wiki/Ragdoll_physics takes a lot of CPU time, and now days games need to be even more realistic.