Sprite raycaster without fisheye

I made a demo of sprite raycasting without a fish-eye effect.

Snap! sprite raycas (berkeley.edu) (I accidentally pressed enter before pressing T)

Instead of using the ray length directly, basically it projects the intersection point onto the direction line, and using the distance from that to the origin instead. It does this using vectors and dot products.


It uses the distance to the projected point when drawing the wall.

For DOT you can use hyperblocks:
untitled script pic (90)

Wow, thanks for the suggestion. I added that in.

Here's my remix.

what's a cross vector in 2d? i know a cross vector is the vector perpendicular to two vectors, but in 2d space that would be impossible.

nevermind searched it up, the cross block probably returns the magnitude of the 3d cross product vector

Yeah.

Instead of


you can just say
untitled script pic (1)
(That's the GO TO [RANDOM POSITION] block with a vector input.)

By the way, I don't understand how this


can be right! The horizontal part is a cross product and the vertical part is a dot product??? That's just weird.

Yep!

Neither do I, but it seems to work.


That's the vector for 45°θ,1r.

Well that's a special case; try it for I dunno 20° and see if what you get is right.

Woops! It doesn't work there:


But is this right?:

All I did there was swap the SIN OF and COS OF in the VECTOR in the CROSS:

You can check with my original implementation of that block. It’s probably correct. I don’t actually know if my block works. It’s never actually used in the project, and it’s just there because at one point i was considering making the sprite dir variable a vector instead of an angle.

Also I noticed that the change variable block doesn’t have hyperblocks support.

I added the ability to elevate up/down. Drawing walls accounting for elevation was quite simple, actually. But in this project there can only be one wall per row, so it works but it doesn't work. I think that can only work with adequate performance with a grid-based map. Don't know how to draw floors/ceilings yet even in a grid-based map, I'll try to figure that one out.

Press x/z to elevate up/down

2D or 3D?

I'm planning to make it so it would be a 2D map, but each cell would have attributes for floor and ceiling height.

Ah.

I'm currently looking for a Python raycaster.

I like how fast this raycaster is, but it isn't really all that easy to use. You can't move left and right just by changing the player's X or Y. There's just a lot of math that isn't really concealed behind a curtain and so you are technically forced to decipher it.

???
Are you talking about the sprite x and sprite y variables? I forgot to delete them. The variable that controls the player position is the "player pos" variable. It's a 2-item list/a vector

I would try to comment my Snap! code if it wasn't such a hassle.
Also I wrote an explanation of what a lot of the math is doing on my post.

I mean, alright. I guess you should maybe push out an update later on to make all the math into a block, just like what @joecooldoo did with his raycaster block (I think it was him?).

I think so, except that it turns counterclockwise instead of clockwise. (That's because the formulas you used are built around math-style angles, ccw from east, rather than orienteering-style angles, cw from north.)

Easiest fix is just use the negative of the angle throughout.

In sine, yeah, but not really in cosine, since cosine -x is the same as cosine x.