Discuss Scratch

qwertycodechamp90411
Scratcher
100+ posts

Raycasting

I'm making a raycaster, and the walls are warping. I've tried multiplying by cos(dir) but it just molds all of the world together.

https://scratch.mit.edu/projects/984144000/ (3 zeroes at the end lol)

Useful Links: Text Generator ——— Encoders/Decoders (Normal, Case Sensitive) ——— New Math Blocks ——— Comment what next on my profile!
Wait, we’re at 900 million projects? So close to 1 billion projects uploaded to the server!

<((x) ^ ((1) / (y))::operators) = ((y) √ (x)::operators)> // is false if x < 0???
Hi! I'm qwertycodechamp90411. I'm most active on the suggestions forum and the help with scripts forum, because I like to help other people and improve scratch! I like to think I'm good at scratch, but there's a lot I don't know/understand (how on earth do scrolling platformers work lol). As a general rule of thumb, I should have the answer if it's math related, because I'm a very stereotypical nerd when it comes to math.
Malicondi
Scratcher
1000+ posts

Raycasting

The problem is you're only comparing the direction of the ray. The direction of the ray is relative to the direction of the player, so to get less warped walls, you have to change this:
add ((distance to (player v)) * ([cos v] of (direction))) to [dist v]
to this:
add ((distance to (player v)) * ([cos v] of ((direction) - ([direction v] of (player v))))) to [dist v]
This should fix the warping, hope this helps!
Edit: the reason why it's still slightly warped is because you're using
move (5) steps
This is quite a big step, and trades accuracy for rendering speed. You can keep it at 5 steps, or lower it to 2 or 3 for less warping.

Last edited by Malicondi (March 26, 2024 03:06:16)


post #1000 post #100 i help in the forums post #1 post #500 0 second ninja
I recommend reading jvvg's essay about the scratch team before complaining, as it may change your opinion and provide insight on the topic.

coming soon :)


qwertycodechamp90411
Scratcher
100+ posts

Raycasting

Malicondi wrote:

The problem is you're only comparing the direction of the ray. The direction of the ray is relative to the direction of the player, so to get less warped walls, you have to change this:
add ((distance to (player v)) * ([cos v] of (direction))) to [dist v]
to this:
add ((distance to (player v)) * ([cos v] of ((direction) - ([direction v] of (player v))))) to [dist v]
This should fix the warping, hope this helps!
Edit: the reason why it's still slightly warped is because you're using
move (5) steps
This is quite a big step, and trades accuracy for rendering speed. You can keep it at 5 steps, or lower it to 2 or 3 for less warping.
Thank you so much! I forgot to add the not to the move -0.5 block as well, now it works great!

Useful Links: Text Generator ——— Encoders/Decoders (Normal, Case Sensitive) ——— New Math Blocks ——— Comment what next on my profile!
Wait, we’re at 900 million projects? So close to 1 billion projects uploaded to the server!

<((x) ^ ((1) / (y))::operators) = ((y) √ (x)::operators)> // is false if x < 0???
Hi! I'm qwertycodechamp90411. I'm most active on the suggestions forum and the help with scripts forum, because I like to help other people and improve scratch! I like to think I'm good at scratch, but there's a lot I don't know/understand (how on earth do scrolling platformers work lol). As a general rule of thumb, I should have the answer if it's math related, because I'm a very stereotypical nerd when it comes to math.

Powered by DjangoBB