Raycasting?
Controls:
- arrow keys to move
- mouse to look around it will eventually reach the border, you have to center the mouse again
- x for viewing map
- d for more detailed stats
about
After trying to make raycasting the wrong way, I came up with this method.
I really don't know if thats the correct way of doing it. My idea was to have rays being shot from the player, when they hit a wall the stop and draw a line in the center at the screen + index of the ray, also the further away the ray went, the smaller the line will be. So that make a pretty good illusion of 3d in a 2d space. You can poke around with the values like the field of vision, amount of samples taken (rays shot), the stretch of the screen and many other.
But I am having this fisheye issue. I guess you noticed that the prespectiv isn't always correct. sometimes it gets this weird round edges. I dont really know how to fix that. Also I dont know how to have walls with diffrent colors, or have a wall which is red on the left side a dark red on the right.
thanks for your interest
To fix the fish-eye effect, calculate rays in a way that ends of all rays form a straight line instead of an arc. I did this by adding camera_direction_vector and a fraction of a camera_perpendicular_vector. I know it's hard to describe, so I put a few illustrations and description here.
If you know the distance of the ray d
and the relative angle of the cast a
, then to get a distance D
as though it were projected onto a 2D line instead of a sphere, you want D=d/abs(sin(a))
.
[Please log in to post a comment]