Example

Heres an example on how you can use this module!

Head into Roblox Studio! Create a Frame and name it "Box". Set its AnchorPoint to 0.5, 0.5 and set its position to: UDim2.new(0.827, 0, 0.499, 0)

Now create a LocalScript, lets get coding! I also added a Folder named "Points". Which will contain our Intersection point frames.

Here's the code in our LocalScript!

local RayCast2 = require(path.to.module) local Box = script.Parent local ScreenGui = script.Parent.Parent game:GetService("RunService").Heartbeat:Connect(function() Box.Rotation += 0.2 ScreenGui.Points:ClearAllChildren() local ray = RayCast2.new(Vector2.new(0, 225), Vector2.new(500, 225)) ray.Visible = true local hit, pos= ray:Cast(ScreenGui, {Box}) if hit and pointPosition then local pointFrame = Instance.new("Frame") pointFrame.Name = "Point" pointFrame.BackgroundColor3 = Color3.new(255, 0, 0) pointFrame.Size = UDim2.new(0, 10, 0, 10) pointFrame.AnchorPoint = Vector2.new(.5, .5) pointFrame.Position = UDim2.new(0, pos.X, 0, pos.Y) pointFrame.ZIndex = 2 pointFrame.Parent = ScreenGui.Points end end) Result (Screenshot)

The red point frame will always be located at the point of intersection of the ray and the Box frame!

Last updated