? Raycasted vision? (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password
This website has been moved, please see this post

Raycasted vision?

  • #1 ✎ 30 AGAaron I need to make a raycast in my game to give my AI vision that conforms to crevices and the general shape of what it's looking at. Other options would seem to be much less ideal. I think I understand the general principle, but I am not certain about implementation with the tools SB provides & I've not done this before in general. My best guess is that I have to move what we could imagine to be an invisible cursor that goes down a straight path. In my implementation I plan to check every 8 pixels. Or if I can figure it out I will do the DDA algorithm. To check that area I will be moving a collide box over each check area. Since this is a hitbox moving to what might be 40 spots each frame sounds like it might be taxing, but I've really no clue. Does this technique ever involve a hitbox like this? I imagine it doesn't and there might be a better way...? Here is a picture I made representing what I want. The yellow dots are cases of the player being caught. http://i.imgur.com/LITUjSM.png Thanks in advance for any help! Posted
  • #2 ✎ 129 jamieyello First Day Joined on the very first day of SmileBASIC Source Website Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies You could get the XY coordinates of you and the enemy and make some kind of line drawing algorithm to check for walls using GSPOIT in between the two points. So you could make a for loop and go through all the enemies, and inside the for loop you could have your line drawing algorithm (drawing a line with GSPOIT) checking for walls in between you and the enemy, and if a wall is detected the enemy would remain unaware of your position. Maybe as a bonus you could make it so if it loses sight of you it goes to the place it saw you last before resuming patrol. There is probably a more optimized way, but maybe not. It might be good enough. Or replace GSPOIT with whatever other method you have of detecting walls. Giving enemies full on vision though? That'd be interesting but probably not very practical. Posted Edited by jamieyello
  • #3 ✎ 30 AGAaron
    You could get the XY coordinates of you and the enemy and make some kind of line drawing algorithm to check for walls using GSPOIT in between the two points. So you could make a for loop and go through all the enemies, and inside the for loop you could have your line drawing algorithm (drawing a line with GSPOIT) checking for walls in between you and the enemy, and if a wall is detected the enemy would remain unaware of your position. Maybe as a bonus you could make it so if it loses sight of you it goes to the place it saw you last before resuming patrol. There is probably a more optimized way, but maybe not. It might be good enough.
    GSPOIT does not render on a line, it checks the color of the pixel that exists there. I don't see the point of doing that as opposed to a hitbox that travels along a line because it would still need to do just as many checks on top of me having to render a color map.
    Posted
  • #4 ✎ 129 jamieyello First Day Joined on the very first day of SmileBASIC Source Website Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies Yeah don't use gspoit use something better if you can. Posted
  • #5 ✎ 30 AGAaron Not to dissuade you of giving more advice, I think you have a good idea of what I'm going for & it's certainly nothing new. Check out this demo I found that shows how raycasting works in the overlay. Try it with Firefox as it uses WebGL: http://leftech.com/raycaster See how it sends out all those lines? Each one interprets data about what kind of objects or textures intersect that line & how far they are. They can be used for creating 3D environments like this (and indeed is the method by which calc84maniac's Spooky Maze was created), but is also used in many modern games to calculate bullets trajectories and to see what they hit. It is also used for the exact purpose I am using it for. If I don't think of a better idea by tomorrow, I'll make a test of my hypothesized solution. I have a feeling there is a better solution though and I'll have a dig through Spooky Maze to see if I can grasp how he does it. Posted
  • #6 ✎ 30 AGAaron Update to emphasize what I'm going for here: http://i.imgur.com/0avyvXh.png The pink dots represent each time I send the 1x1 collider to that spot to check for any other colliders. On the left you'll notice an edge case where the line seems to go through the wall. This is a representation of a worst case scenario using this system of checking every 4 pixels (as it is shown here). If I use DDA (Digital Differential Analyzer) in place of my simple check for every 4 however, it will check on each line of the main grid that intersects the ray. I'm not counting on me accomplishing that, I'm not even sure this is a good way about doing the rays in general since I've never done them. If my method turns out miles easier than tearing out my hair over some new algorithm, I'll probably do it if it's 'good enough'. Using DDA looks something like this, by the way: http://i.stack.imgur.com/5HHvN.png Posted