Basically, I’m trying to make it so if a Raycast hits the exact Vector3 position of a part it will do something.
In other words;
Part.Position = 0,16,0
Ray casts to the part from above
I want it to return 0,16,0 instead of 0,15,0
I was using Ray.new this entire time, and I heard about the more recent RaycastResults and how it’s better than the old Ray.new so I wanted to try it out.
Thanks for reading.
so you basically want the raycast to return the position of the “Hitted Part” and not where it “hit”?
The new workspace.Raycast returns a RaycastResult, which includes the instance hit.
Example code for what you want to do (assuming you define part and raycastParams):
local raycastResult = workspace:Raycast(part.Position, part.CFrame.LookVector*50, raycastParams)
if raycastResult then
if raycastResult.Instance:IsA("BasePart") then
print("Part position:", raycastResult.Instance.Position)
else
print("Hit terrain!")
end
end
2 Likes
I think my brain wasn’t working at the time, but still, thank you for the answer! This is what I needed!
1 Like