Hello! I was wondering if there is something wrong with my computation in my code or is it just really roblox’s raycast that is being weird.
I am raycasting from the ai’s pivot TO its lookvector multiplied to 3.5 studs (the forward cframe of the ai)
BUT it seems to detect some weird calculations
local types = require(game:GetService("ReplicatedStorage").types)
type AI = types.AI;
local CheckPoints = ({});
local CheckConnection : RBXScriptConnection;
local lastTick = tick();
local Private = ({});
Private.Started = false;
function Private.CreateDebugPoint(Position : CFrame | Vector3, Color : Color3)
local Part = Instance.new("Part");
Part.Size = Vector3.new(1,1,1);
if typeof(Position) == "Vector3" then
Part.Position = Position;
elseif typeof(Position) == "CFrame" then
Part.CFrame = Position;
end
Part.Anchored = true;
Part.CanCollide = false;
Part.CanTouch = false;
Part.CanQuery = false;
Part.Color = Color;
Part.Material = Enum.Material.Neon;
Part.Parent = workspace;
return Part;
end
function Private.CheckPoint(AI : AI, PositionInit : CFrame)
local RayPar = RaycastParams.new();
RayPar.FilterDescendantsInstances = {AI.Character};
RayPar.FilterType = Enum.RaycastFilterType.Exclude;
RayPar.RespectCanCollide = true;
local NewRaycast = workspace:Blockcast(PositionInit, Vector3.new(1,1,1), (PositionInit + PositionInit.LookVector*3.5).Position, RayPar)
if NewRaycast then
print("oo")
Private.CreateDebugPoint(NewRaycast.Position, Color3.fromRGB(255, 0, 0));
else
print("None")
Private.CreateDebugPoint(PositionInit + PositionInit.LookVector*3.5, Color3.fromRGB(47, 255, 0));
end
end
function CheckPoints.Start(AI : AI)
if Private.Started == false then
Private.Started = true;
else
return
end
CheckConnection = game:GetService("RunService").Heartbeat:Connect(function()
if tick() - lastTick >= .3 then
local ForwardedCFrame = AI.Character.PrimaryPart.CFrame
Private.CreateDebugPoint(ForwardedCFrame, Color3.fromRGB(21, 255, 247));
Private.CheckPoint(AI, ForwardedCFrame);
lastTick = tick();
end
end)
end
return CheckPoints
Help would be much appreciated!