Currently I’m raycasting from a position above the waypoint downwards in order to detect the height of the smooth terrain underneath the waypoint.
Everything works, except I can’t change the position of the waypoint to the position of where the raycast ended?
Module script
local function RayCast_Downwards_To_Check_Terrain_Height(Waypoint, WaypointBall)
local RayOrigin = Waypoint.Position + Vector3.new(0,100,0)
local RayDirection = Vector3.new(0, -150, 0)
-- Build raycast paramters
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character:GetChildren(), WaypointBall}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
-- Cast Ray
local raycastResult = workspace:Raycast(RayOrigin, RayDirection, raycastParams)
if raycastResult then
if raycastResult.Instance.Name == "Terrain" then
return(raycastResult.Position) -- End position of raycast
end
end
end
local Waypoints = Path:GetWaypoints()
for _, Waypoint in pairs(Waypoints) do
local RayEndPos = RayCast_Downwards_To_Check_Terrain_Height(Waypoint) -- Call the raycast function
Waypoint.Position = RayEndPos -- Change waypoint position to raycast end point position
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = Waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace
end