Last week I reported that I had less time to work on implementing raycasting, which meant less time to debug what I was doing wrong.
I knew I was similarly not going to have as much time to do development this past week, but I made some big progress.
Sprint 12: Pre-production and initialization
Planned and incomplete:
- Move player in dungeon view
Fairly quickly after my last report, I discovered a few things about how I was implementing the raycasting incorrectly.
First, instead of arbitrarily assigning a “camera plane” and then rotating it and hoping that it stays in place relative to the player’s direction, I determine the camera plane based on the direction of the player.
And I had those vectors defined incorrectly.
Basically, if I treat North/Up as the default, then I want negative Y to mean forward, and positive X to mean to the right. East should similarly treat positive X as forward and positive Y as to the right. And so on.
I realized at one point that the values I was getting when I was casting rays were weird, and I had to draw everything out because it was getting hard to think about direction and positive/negative values.
Once I got those vectors right, then I had walls drawing, but only on half of the screen.
I added logs and realized a few issues with the code.
One, the player’s position is represented as whole values. That is, the player could be at position (2, 4), which would represent being in the corner of a cell in the grid that represents the dungeon layout.
So now I start the ray at (2.5, 4.5), the center of the cell.
Two, part of the algorithm was dividing by zero, which is why the left half of the screen was missing any rendered lines.
Then I made a change, but the side walls and the back walls were not lining up.
Unfortunately, while I was digging through logs and trying certain changes, I then reverted a change, and suddenly everything looked relatively right?
I wish I could say why.
I then tried to do a simple change to add the stone wall texture, but my simple change was too simple, and everything was distorted.
And as you can see, the algorithm seems to be drawing the walls outside of the viewport.
I have since read through the existing algorithms and think I see how to address this issue.
I also want to make sure that the horizon line isn’t centered. Centered is a bit boring.
And currently if you are facing a wall in your grid cell, it fills the entire view area, and I want you to be able to see some floor in the cell you’re currently in.
But so far, I made good progress, and the neat thing is that I was able to maneuver through my test dungeon level, and after I get the wall textures right, I can focus on the floor and ceiling.
Thanks for reading!
—
Want to learn when I release The Dungeon Under My House, or about future Freshly Squeezed games I am creating? Sign up for the GBGames Curiosities newsletter, and download the full color Player’s Guides to my existing and future games for free!
One reply on “Freshly Squeezed Progress Report: Raycasting Actual Walls”
[…] last week’s report, I showed off some progress I made in rendering the walls of the sample dungeon I […]