January 19, 2021, 09:47:58 PM

### Author Topic: [bmx] Boxes Collide by Leon Drake [ 1+ years ago ]  (Read 1422 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bmx] Boxes Collide by Leon Drake [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : Boxes Collide
Author : Leon Drake
Posted : 1+ years ago

Description : An Alternate way to detect is two 3d Bounding boxes are colliding using only a simple if. Accepts 2 types of coordinates defaults are x,y,z,w,h,d

where w h d are the distances from x y z

the other way uses w h d as 3d coordinates not distances from x y z

Code :
Code: BlitzMax
1. Function boxescollide(x#,y#,z#,w#,h#,d#,x2#,y2#,z2#,w2#,h2#,d2#,coordtype=True)
2.
3.
4. If coordtype=True Then
5.
6. w# = x#+w#
7. h# = y#+h#
8. z# = z#+d#
9.
10. w2# = x2#+w2#
11. h2# = y2#+h2#
12. z2# = z2#+d2#
13.
14.
15. EndIf
16.
17.
18.         If x# <= w2# And w# >= x2# And y# <= h2# And h# >= y2# And z# <= d2# And d# >= z2# Then
19.         Return True
20.         Else
21.         Return False
22.         EndIf
23.
24.
25. End Function

IPete2(Posted 1+ years ago)

Don't forget to add in Z2# in the function call!IPete2.

Leon Drake(Posted 1+ years ago)

LOLZ oh man.