Layering issues

When an overlayed sprite is shown near the edge it is layered under a wall. The layering is determined by the direct distance from the player. I think this might be caused by the weirdness with raycasting, or it may be because of the fish-eye effect?
Any thoughts on what could be causing this/ how to stop it?
image

5 Likes

Raycasts’ “hit” output gives the distance to the object center instead of the distance to the collision point; perhaps it’s something to do with that?

4 Likes

Hmmm, so this is just off the top of my head, and I have know idea if it would work, but could you maybe compensate for the blockiness by making the pixels/lines (or whatever you are using to make the walls) lower if they are farther to the right or something like that and higher if they are father to the left. Does that make sense?

Another idea that I had was to use trapezoidal integration of some kind. Idk exactly how that would be implemented, but I had the idea because the wall looks about like a graph using a left or right riemann’s sum, but if you used trapezoidal integration (since you can’t let n go to infinity, as would be ideal), it would at least make it less jagged, you know? In case you have absolutely no idea what it is I’m going on about, it’s calculus. Basically, if you try to find the area underneath a curve on a graph by using only the values at certain points, you won’t end up with the exact area, but rather an over or under approximation of the area, because you would be assuming that all values between two points are equal to the value at either the leftmost or rightmost point, if that makes sense. That appears to be about what’s going on here. However, if you can’t get the value at EVERY point (infinitely many points) under the curve, then you can still compensate by using trapezoidal approximation, which approximates the area by using trapezoidal to connect the points instead of rectangles. Basically, drawing straight lines between points instead of actually having it curve. Idk if any of this would work, or if I have just COMPLETELY confused you (it confused me when I first learned it), but I hope this helps at least a little bit.

Here’s some external explanation of what I talking about, because I’m almost certain I haven’t explained it in a way that made any sense (if you’re interested, you could probably check out khan academy, too)

https://math24.net/trapezoidal-rule.html

If you want additional explanation or formulas, or help with the math of it, I’d be happy to help (as much as I can, given that I am bad at explaining things)

4 Likes

Yeah I did actually think of this before, but I have no clue on how to actually make it. right now I have an object for each vertical line, so to make straight lines I would need an object to form a line between each ray cast as well as an object to fill in the area. thinking about it, I’m not sure it would be able to fill in very well + cause a lot more lag :frowning:
image
This is what you’re talking about I think, the only problem would be filling in the missing space between lines (cause rectangles)

I still suggest raycasting to the player and if it hits something else to hide it.

1 Like

The only reason I’m not doing that is because the object has width, and I want it to be partially visible if only some of the object is behind a wall.

idk if this makes sense lol

1 Like