Circular Collision

Blitz3D Forums/Blitz3D Beginners Area/Circular Collision

Q(Posted 2005) [#1]
Can anyone direct me to a tutorial, or perhaps post some code on how to do 2d circular collision?

Thanks.


BlackJumper(Posted 2005) [#2]
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 ;-)


Q(Posted 2005) [#3]
I need to see a demo. Any help would be greatly appreciated.


Rob Farley(Posted 2005) [#4]
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



Q(Posted 2005) [#5]
What I meant is circle to square collisions. It has been awhile since i've done any math, sorry.


Sir Gak(Posted 2005) [#6]
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.


octothorpe(Posted 2005) [#7]
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.