Circular Collision
Blitz3D Forums/Blitz3D Beginners Area/Circular Collision
| ||
Can anyone direct me to a tutorial, or perhaps post some code on how to do 2d circular collision? Thanks. |
| ||
Not quite sure what you mean by that... ... but you might be looking for an 'EntityDistance()' equivalent. In other words, anything that enters a specific radius around the centre of an 'object' can be considered to have collided with the object. You can do this using basic pythagoras... dist = sqrt( (Xobject - Xtarget)^2 + (Yobject - Ytarget)^2 ) if dist < CollisionRadius then .... It may even be more efficient to ignore the square root part and compare to CollisionRadius squared... distSquared = (Xobject - Xtarget)^2 + (Yobject - Ytarget)^2 if distSquared < CollisionRadius^2 then .... Obviously you could wrap this up in a For Each loop around a target type and examine (Xobject - target\Xtarget)^2 + (Yobject - target\Ytarget)^2 I don't have Blitz installed on this laptop or I would have knocked you up a quick demo... I am sure someone with a feuding Xmas family to avoid will be along shortly to rectify this ;-) |
| ||
I need to see a demo. Any help would be greatly appreciated. |
| ||
Valorden, how lazy are you?Function CirclesOverlap(x1#,y1#,r1#,x2#,y2#,r2#) x=(x1-x2) y=(y1-y2) d1 = Sqr((x*x)+(y*y)) d2 = r1+r2 If d1<=d2 Then Return True Else Return False End Function |
| ||
What I meant is circle to square collisions. It has been awhile since i've done any math, sorry. |
| ||
Maybe what you are looking for, is the following? Collisions 1,2,3,2 ;Object 1 (typically your camera, with a set radius) colliding with type 2 objects (everything else?), with an ellipsoid to box collision (ie "3"), and slide (ie "2") as the result. |
| ||
For circle-to-square collisions you can do 4 circle-to-line collisions, which you should be able to find the math for with Google painlessly. |