Help with live 3D raycast engine and projecting rays directionally

I’ve been developing a live renderer which is targeting more for visually pleasing looks.

I have been using camera:ScreenPointToRay() to project the rays but have seen problems with using it, one example is how the image can stretch if the viewport is manipulated.

My engine uses a 1:1 ratio rather than the entire viewport and I was hoping if someone has a solution to directions for the rays.


You would have to use a editableImage.AbsoluteSize.X : camera.ViewportSize.X ratio which it seems like you’re doing but try this and see if it works:

local xRatio = editableImage.AbsoluteSize.X / camera.ViewportSize.X
local yRatio = editableImage.AbsoluteSize.Y / camera.ViewportSize.Y
local rayDirection = camera:ScreenPointToRay(rayPoint.X * xRatio, rayPoint.Y * yRatio).Direction * renderDistance

Thank you for replying but I have found a better solution, still a wip but it no longer relies on viewport sizes

Heres my solution

local rayPoint = Vector2.new((xIndex / editableImage.Size.X - .5) * fieldOfView, (yIndex / editableImage.Size.Y - .5) * fieldOfView)
local rayDirection = (camera.CFrame * CFrame.Angles(-math.rad(rayPoint.Y), -math.rad(rayPoint.X), 0)).LookVector * renderDistance

Theres still problems with warping when leading to the corners of the screen, but atleast I can now use a custom ratio

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.