Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to control ray cast thickness?

Asked by 4 years ago

I'm currently trying to make a mob to follow a player and move around obstacles using ray casting. However, there was been a problem with it not checking whether or not the space that it can walk through will fit because the ray is like 1 millimeter thick. So I was wondering if there was a way to change the thickness of the ray to fit the entire width of the mob.

1 answer

Log in to vote
2
Answered by 4 years ago

I don't think there is a way to control the thickness of a ray, however, you can use TWO rays.

Here's how it works, create 2 rays, one at the very far left of the mob, and one at the very far right.

Cast them in the direction the mob is currently moving at, then check if BOTH of the rays return nil, if one of them returns a hit, it would mean the path is too narrow to move through.

An example would be like this:

local Way1 = Ray.new(Start + Vector.RightVector*Radius, (Vector.LookVector+Vector.RightVector*Radius) * (Start-End).magnitude)
local Way2 = Ray.new(Start + Vector.RightVector*-Radius, (Vector.LookVector+Vector.RightVector*-Radius) * (Start-End).magnitude)
local Blocked1 = workspace:FindPartOnRayWithIgnoreList(Way1, Ignored, false, true)
local Blocked2 = workspace:FindPartOnRayWithIgnoreList(Way2, Ignored, false, true)

if not (Blocked1 or Blocked2) and Start.Y - End.Y < 1.5 then
    return true
else
    return nil
end
1
I'd probably just explicitly imply "CFrame". Everything else is absolutely awesome! Farsalis 369 — 4y
Ad

Answer this question