MiniB3D Sphere collision example
BlitzMax Forums/BlitzMax Programming/MiniB3D Sphere collision example
| ||
Yup. Just a quickie I needed for a project. Just hacked it together from the primitives example :) Control sphere with keys, it turns red when there's collision. Here goes: |
| ||
Havent tested this yet but you are using the following calculation for the distance:Local dist:Float = relx * relx + rely * rely + relz * relz If I remember geometry well enough, you should take 3th root of that. Since you compare it to the 2nd power of minDist, you actually took the 2nd root. |
| ||
You know, with sin and cos, you could prevent the two spheres from going through one another. |
| ||
Havent tested this yet but you are using the following calculation for the distance: Local dist:Float = relx * relx + rely * rely + relz * relz If I remember geometry well enough, you should take 3th root of that. Since you compare it to the 2nd power of minDist, you actually took the 2nd root. EDIT: Nope, on second read, I misread his code. You're right. |
| ||
Danielwooden, why on earth would you mess with sin and cos here? That's an awfully slow way to calculate the distance. |
| ||
Yup. No need for sin and cos. And you can still do the velocity thing if need be. (To prevent collision to fail on two moving objects passing through each other in rare cases.) |