I don’t know why on God’s green earth this is happening, and I’ve just given up trying to find the issue, and yes, it’s doing exactly what the title of this post says.
Basically, I was trying to make a function that can check to see if the humanoid can simply walk straight to the player by first raycasting from the figure to the player to see if there’s nothing in the way and then (this is the part that doesn’t work) raycasting along the “line” while being directed down to see if there’s ground there.
I’ve even replaced the raycast with spherecast, and it did the same thing!
The function:
local function Straight_line_check(start_pos, target_pos, target_model)
local params = RaycastParams.new()
params.FilterDescendantsInstances = {figure, target_model}
params.FilterType = Enum.RaycastFilterType.Exclude
local direction = target_pos-start_pos
local RAY = workspace:Spherecast(start_pos, 2, direction, params)
local success = pcall(function()
local A = RAY.Instance
end)
if success then
return {}
else
local step = 2/direction.Magnitude
local current = step
local Points = {}
repeat
local result_pos = start_pos + (direction*current)
local cast = workspace:Spherecast(result_pos, 1, Vector3.new(0, -4, 0))
local success, Error = pcall(function()
local A = RAY.Instance
end)
if not success then
return {}
-- local wrong_pos = result_pos-Vector3.new(0, 4, 0)
-- local part = Instance.new("Part")
-- part.Parent = workspace
-- part.Position = wrong_pos
-- part.Anchored = true
-- part.CanCollide = false
-- part.CanTouch = false
-- part.CanQuery = false
-- part.Shape = Enum.PartType.Ball
-- part.Material = Enum.Material.Neon
-- part.Size = Vector3.new(3.5, 3.5, 3.5)
end
local point = PathWaypoint.new(result_pos, Enum.PathWaypointAction.Walk, "Unblocked")
table.insert(Points, point)
current += step
until current >= 1
return Points
end
end
Here’s a Desmos graph of how it would look like: