Heyo. I want to get the position of terrain I hit with a raycast. My issue is that the position is 0,0,0 when the code has clearly hit a bit of terrain.
I have looked at all of these so far and have tried solving this for a good hour now:
- RaycastResult
- Terrain:ReadVoxels
- How do I find a Terrain Voxel's Position with Raycasting?
- Detecting where a ray hits smooth terrain
- RayCast and terrain detection
- How can I orientate a part according to terrain?
For more clarification, I am making a boss fight attack. I need to get the position of the terrain from a raycast so I can make a part go to the position where the raycast hits.
Here is the code. Also, it is a server script:
local rayOrigin = script.Parent.HumanoidRootPart.Position
local rayDirection = Vector3.new(0,-100,0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {script.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
local positionOfSurfaceHit = hitPart.Position
local materialFromRay = raycastResult.Material
print(positionOfSurfaceHit)
print(hitPart)
print(materialFromRay)
end