How do I fix this problem? (image in post)

Help!

I am currently trying out a bit of "ray tracing" by following this example, but I am stumped on a problem that I haven't been able to iron out.

Here's an image of the problem.

I've tried adjusting the angle that I use to find the vertices, I've tried using some maths to sorta extend the sides of the shadows so they meet, but I still end up with this problem to varying degrees. The only way I can fix it is by extending the walls to overlap in the room editor, but I would rather not have to do this (due to some walls being move-able, etc).

Thanks for your time!

Posted Aug 26, 2019, 12:30 AM UTC · edited

24
JP_Rose•

I would need to look at code to give a sure fix, but I might be able to provide a workaround without changing code. It appears you are using multiple square wall objects placed side-by-side to create your walls. Try using a single wall object and stretching it to the desired length of the wall. I think that will fix your shadow issue, but it will also stretch your wall texture. You could either make the wall objects invisible and use tiles to show the walls or create multiple wall objects of varying lengths to not have stretched wall sprites.

2
AgentLymOP•

That does fix my shadow issue, but I'd rather not have to do that due to gameplay reasons (some walls are stand-alone/movable/etc). Thanks for the thought though!

3
TheOtherHarpo•

To preface this...I don't think you should follow the tutorial you linked to. There are a number of errors, it's outdated for GMS 2, and there is a better tutorial from yoyo games here (this one uses the tilemap to find the x and y coordinates of the walls but you can keep the with(obj_wall) loop logic from the tutorial you were using and just use that in place of the for loop that loops over all of the tiles. That said, I will tell you what they are doing incorrectly in this code that is causing errors.

This bug is a combination of three problems. First, the use of the bbox variables does not line up correctly with the corners of the actual object sprite. Not sure why that is, but you're going to need to replace those values (e.g. bbox_left is x - sprite_xoffset and bbox_top is y - sprite_yoffset).

Second, the shadowsize value in the demo code is too small. I upped it to 20000.

Third, they don't draw enough vertices and the order they use is not correct. You should draw the vertices in order, rotating around the points of the object instead of crossing diagonally over the object (e.g. left top, left bottom, right bottom, right top). Though this isn't 100% necessary to change, you are more likely to see gaps if you do not. The important part here is they are missing two vertices. You basically need to repeat the first two draw_vertex calls so if this is the first set of vertices you draw:

draw_vertex(x - sprite_xoffset, y - sprite_yoffset);
var dir = point_direction(other.x, other.y, x - sprite_xoffset, y - sprite_yoffset)
draw_vertex(x+lengthdir_x(other.shadowsize,dir), y+lengthdir_y(other.shadowsize,dir));

you need to call that code again right before draw_primitive_end to draw the final vertex and fully fill this in.

edit: added more info on the order of vertex drawing.

2
AgentLymOP•

Thanks so much for the detailed reply! I'm at work now but I'll check out your link when I get home.

1
AgentLymOP•

I've implemented your suggestions, and unfortunately the problem still existed. However, I was able to fix this problem by temporarily extending the side of the wall outward while calculating the final projection positions. Thanks again!

1