I'm trying to find the exact position of where a ray hits a part. I first tried taking the Y position and the Z position of the rays origin and the X position of the part to find the exact position hit, but ofcourse this method won't work unless the ray is casts along the x axis. I need to be able to have rays at all different angles and find the exact position of the of where the ray hits the part.
local MovingPart = game.Workspace.TestPart --Part I want to move to the position hit
local finish = script.Parent.finish
local start = script.Parent.start
local rayOrigin = start.Position
local rayDestination = finish.Position
local rayDirection = rayDestination - rayOrigin
local ray = Ray.new(rayOrigin, rayDirection)
local part = workspace:FindPartOnRay(ray)
local ypos = start.Position.y
local zpos = start.Position.z
local xpos = part.Position.x
MovingPart.Position = Vector3.new(xpos, ypos, zpos)

1 comment
Thank you!