Hello, I'm doing a 3D game and I'm having trouble making 3D raycasting. In case, I want to do to the camera, to know if there is no object between the camera and the player. For this I need to find a vertex that represents the angle and check on the map whether there are obstacles or not. The camera stores the two-axis angle: Y-axis (modified with horizontal mouse movement, X-axis of the screen in the 2D plane) and X-axis (modified by vertical mouse movement, Y axis of the screen in the 2D plane) . I can do raycast from any of these angles alone, but I can not put them together to make raycast in 3 dimensions. The problem is that both share the Z (the sine of the Y axis and the cosine of the X axis). If I multiply the two between them, the result is only correct when the angle Y is 0º or 90º. If not, it gets inverted.
What formula should I use to calculate the Z value?