I’ve been trying to understand raycasts for 1/2 hours and still could not understand them
I still can’t figure out how to make a raycast that actually works
This is the code that doesn’t work:
local part = workspace:FindFirstChild("RaycastPart")
local function FireRaycast()
local rayOrigin = part.Position
local rayDirection = Vector3.new(100,0,0)
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
if raycastResult then
local hit = raycastResult.Instance
print(hit)
end
end
FireRaycast()
yea, you can have the raydirection be the parts lookvector
example code:
local part = workspace.raypart
while wait() do
local ray = workspace:Raycast(part.Position, part.CFrame.LookVector*5)
if ray then
local inst = ray.Instance
print(inst.Name)
end
end