Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I fix this ScreenPointToRay issue?

Asked by
Derci 5
9 years ago
local frame = script.Parent.Frame;
local cam = workspace.CurrentCamera;

game:GetService("RunService").RenderStepped:connect(function()

        local camCF = cam.CoordinateFrame;

        local xOffset = (frame.AbsolutePosition.X+(frame.AbsoluteSize.X/2));
        local yOffset = (frame.AbsolutePosition.Y+(frame.AbsoluteSize.Y/2));
        local depth = 6;

        workspace.Part.CFrame = CFrame.new(cam:ScreenPointToRay(xOffset, yOffset, depth).Origin);
end);

The code above works well enough, except for when the object is moved to the sides of the screen.

Image Example

Image Example 2

As you can see from the image above, when I move the part to the sides, it moves closer to the screen making the part appear larger than it is. What's the best way to make it retain the same distance away from the screen no matter where I move the frame?

Answer this question