I’m developing a ‘block-based game’ (something like Minecraft), and I got stuck on one thing:
Supposing I have control of everything in the world (blocks and entities), and every one of them has an AABB (location, size, etc)… how could I get what my mouse is looking/pointing at? The player has a rotation system according to mouse movements. I just don’t know how to get the block/entity I’m looking at.
You can to use a form of ray casting from your eye vector. Basically extend that ray to the distance you want to be able to consider within reach of your player and then test the intersection of that ray with the nearby blocks. The block with the closest intersection should be the one you are focused on.
To test the intersection of that ray with the blocks, you’ll need to check it against each plane on the block. You can use a ray-plane intersection algorithm to accomplish that.
Obviously, try to reduce the number of blocks and planes you test against as much as possible to increase the performance.