Raycasting in a 3d game to create hitscan weapons

Hi I am new here on the forums and I have a question. I have been working on a wolf3d type of game(mostly the level design currently) and I wanted to start implementing gameplay currently my player can move around in the levels and look around and thats it. So I wanted to implement hitscan so the player has to make his way past the guards to complete the level through stealth or killing the guards I would use raycasting for this but I have no idea how I should start because I do not have any theory behind how it works. I know how to use it(I have used other game engines in the past) but I dont know how exactly i would implement this. Any help on this subject is appreciated. Here are some images of how it currently looks:


Your game reminds me the very first blueprint of mine ;D i used raycasting at the very beginning in 2006. You can throw a ray starting from your player’s gun, going forward. You’ll have to compute a bounding volume containing the zoomed bitmap for each enemy. As the ray might go throw some objects, you might find several collision results, you’ll have to sort them and to pick the first one except for the projectiles that purposely go through walls. A ray is similar to an half-line in your case, you need three spatial coordinates for its start and a vector to represent its direction. I can help you to implement a method to compute the collisions between an axis-aligned bounding box and a ray if you want. Where is your source code?

P.S: Maybe this helps.

…aren’t you already using raycasting when rendering the game?

Essentially raycasting is casting a bunch of rays/projectiles in an arc around the camera – these rays/projectiles have a direction they step through and check for collisions – when they hit something they stop and you’ll know the distance they travelled (so that you can draw the walls/etc big/small based on how far away they are from the camera).



Thank you for all the current replies I’ll check out the sources you have given so far.