box collision

Post Reply
User avatar
Kilarin
Member
Posts: 896
Joined: Mon Mar 10, 2014 00:36
GitHub: Kilarin

box collision

by Kilarin » Post

Does the minetest lua api have a built in function to quickly and efficiently check if two boxes intersect given minp an maxp for each?

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: box collision

by rubenwardy » Post

Not that I know of, but the algorithm is pretty easy. If you Google cube-cube collision, you'll find this:

Code: Select all

return (A.min.x <= B.max.x) && 
    (A.max.x >= B.min.x) && 
    (A.min.y <= B.max.y) && 
    (A.max.y >= B.min.y) && 
    (A.min.z <= B.max.z) && 
    (A.max.z >= B.min.z);
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
Kilarin
Member
Posts: 896
Joined: Mon Mar 10, 2014 00:36
GitHub: Kilarin

Re: box collision

by Kilarin » Post

I was just wondering if there was a super fast implementation, since I seem to be doing a lot of this. :)
But, the old fashioned way is pretty fast in lua, I guess I'll stick to it.

thank you

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests