Page 1 of 1

Raycaster firing backwards [Solved]

Posted: Thu Jan 25, 2024 6:45 pm
by Andersonreis42
Hey!

I'm following 3DSage's tutorial and I could solve some issues with the code just fine, and i've managed to make it work. However, sometimes the ray is fired backwards:
ok ray.png
ok ray.png (7.01 KiB) Viewed 4703 times
ray not ok.PNG
ray not ok.PNG (9.34 KiB) Viewed 4703 times
the yellow dash is the player's direction. I think the issue might be caused by the snippets and conditionals regarding to wheter the ray is facing left-right-up-down with given angle since it always happens at the same angle range, but I can't pinpoint the cause!

About the code, i'm casting both horizontal and vertical checks separately because i'm using windows defeault notepad and it tends to get a bit messy...

Thanks in advance for your input!

-EDIT-

Hey guys! I've managed it out.

In function raycastV() the line rx = math.floor((py / 64)) * 64 - 1 should be rx = math.floor((px / 64)) * 64 - 1. I just wrote it wrong!

I'm uploading the correct code incase someone is interested in casting rays.