Discuss Scratch

Extremguy
Scratcher
100+ posts

Raycasting need help

I've made a project that supposed to simulate raycasting basics. Just throw ray depending of your FOV and then stop the ray if they collide with a wall or with the background. The problems is that the rays doesn't seem to appear at all.

https://scratch.mit.edu/projects/182001432/

How it works:
I have my player with it X,Y,Angle,FOV

It's angle is used for moving with sin,cos using scratch angle. We pick the angle and we cut the FOV in two and we subtract the angle
Then we start a loop to do each ray based upon the lenght of the fov. Then we will increase the ray by 10 to go quicker , each time the ray increase it will try to verify if it has collisions by checking if the ray has the same atan2 angle value then the camera angle.

(NOTE: All ray will passes through wall at first , then it will check if it collided by verifying if a wall with it width/height as collided at a certain point in space , then it is supposed to set the good coordinate of the ray)

If it does we then add the distances by calculating the distance between two point and we compare the distances to have the shortest one to have the walls.

Also it seems that my player get stuck ,eventhough it is not colliding with any wall and also my walls doesn't draw for some weird reason.

Problems is that the ray doesn't seem to cast at all. Could you help me on this one? Or maybe it my ray collision. If you have any better options thanks.

Last edited by Extremguy (Oct. 26, 2017 03:22:34)

gtoal
Scratcher
1000+ posts

Raycasting need help

hard to see what's going on with all those simultaneous broadcasts. perhaps try broadcast and wait. Or don't use broadcasts and do it all in one sprite.

Powered by DjangoBB