So I’m following a pretty good tutorial on YouTube, which goes through how to make a 2D character controller. However I’m making a 3D controller, so I need to apply 3D space where appropriate.
Right now I did a sketch of the cuboid (in the tutorial it’s just a quad), and written down the local unit coordinates of each corner point of the cuboid.
Here’s a quick representation I just made in MS Paint:
All those "0.5"s and are the unit positions of the cuboid’s corners. And currently the way I see it, I will have to cast out 3 rays from each point, to detect collision from all possible sides.
Like so:
Here is why I wrote this thread:
A cuboid has 8 corners, which means there will be 24 rays being cast outwards from this single cuboid. And there will be a lot of these. And that’s my concern.
How efficient would this be, in terms of processing power? I know raycasts are rather cheap, but let’s say I have 10 of these cuboids being rendered at the same time. That means there will be 240 rays, and this will just multiple, the more cuboids there are on-screen.
Would this be a problem? And if so, what would be a better way of doing this (detecting collision through casts)?
Now keep in mind, although this may not be a problem processing-wise (at least for a single cuboid). I still need to write some code for every single raycast, and what happens if it hits something. As well as what happens if all casts from a certain direction don’t hit anything (character falling). This means well over 24 lines of very similar (but different) code, just for handing collision. Which I can already imagine would be a nightmare to maintain if one of those raycasts wasn’t working properly.
Just imagine. 24 raycasts, all with very similar coordinates, all with similar casting directions and lengths, all resulting in similar results if they hit something, and one of them doesn’t work and you need to find out which one.
Now before someone says this belongs in the Physics section. This isn’t talking about the actual physics that the raycasts will achieve, but whether using and coding these raycasts is efficient.
Only thing I can think of, would be a boxcast, but I don’t exactly know how I would handle detection from specific sides and how to detect if none of the corners of a certain side hit anything.