so apparently i’ve done alot of research and i did quite a bit of experiment but i am still unable to achieve what i needed to.
what i actually need to achieve is that the intersection point of the raycast getting the position of the area where the raycast stopped hitting not getting the part’s position
i used raycast.Position but instead it just got the direction end position i want like to get the raycasts hit position. if my explanation is not understandable i wish to achieve this:
local raycast = workspace:RayCast(Vector3.new(0,5,0),Vector3.new(0,-10,0))
if raycast then
print(raycast.Position) -- this would return the raycasts hit position and not raycasts instance position
print(raycast.Instance.Position) -- this would return raycasts hit instance position
end
If you want to get the exact position where a Raycast hit a part, you should use the Hit property of the RaycastResult. The Hit property contains information about the instance (like the part) that was hit and the position of the hit.
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {workspace.IgnoreRaycast}
local ray = Ray.new(startPosition, direction)
local hitResult = workspace:Raycast(ray, raycastParams)
if hitResult then
local hitPart = hitResult.Instance
local hitPosition = hitResult.Position
print("Hit part:", hitPart)
print("Hit position:", hitPosition)
else
print("Ray didn't hit anything.")
end
If are confused on how the direction parameter works on the Raycast function this is how it works
local startPosition = Vector3.new(10, 5, 0)
local goalPosition = Vector3.new(0, 5, 0)
local direction = goalPosition - startPosition
local result = workspace:Raycast(startPosition, direction)
if result then
print("Result Position:", result.Position)
end
The normal is a unit vector, pointing outwards from the intersected face. I have no clue what OP is looking for, but I’d wager to say that probably isn’t it.
local StartPos = (workspace.Part.CFrame.LookVector * 20) + workspace.Part.Position
local Direction = Vector3.new(0,-40,0)
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = {workspace.Part,workspace.arf}
RayParams.FilterType = Enum.RaycastFilterType.Blacklist
RayParams.IgnoreWater = true
local Raycast = workspace:Raycast(StartPos,Direction,RayParams)
if Raycast then
workspace.arf.CFrame = CFrame.new(Raycast.Position)
end
also im wondering like after getting the part that the raycast intersected with how do i get like the surface of what i hit like for example it hit the right then it would print as “hit surface right”
I believe you’re confused about how a Raycast works, as Raycast requires vectors, not a cframe.
local start = workspace.start
local direction = Vector3.new(0, 0, -45)
local visualiser = Instance.new("WireframeHandleAdornment")
visualiser.Color3 = Color3.fromRGB(137, 53, 255)
visualiser.Adornee = workspace.Terrain
visualiser.Parent = workspace
local rayParams = RaycastParams.new()
rayParams.IgnoreWater = true
local result = workspace:Raycast(start.Position, direction, rayParams)
if result then
visualiser:AddLine(start.Position, result.Position)
end
I would recommend learning about CFrames and Vectors before fully going onto Raycasts. Originally you were adding extra positions and making the origin position further away.
although your explanation kind of helped me abit, but i just found the way entirely by myself. thanks for your help and all the other who have tried to help!