Hi. I’m trying to make a piggy game and make it so when the player goes behind a wall, the bot will go and walk away. But I don’t how to get the target for the rayCast parameter.
Here is my script:
local function rayCast(target)
local body = target.Parent
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {Bot, body}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(humRootPart.Position, target.Position, raycastParams)
if raycastResult then
if raycastResult.Instance:IsDescendantOf(body) then
return true
end
else
return false
end
end
local function findTarget()
local distance = 33
local target = nil
for i, v in pairs(game.Workspace:GetChildren()) do
local human = v:FindFirstChild("Humanoid")
local humanoidRootPart = v:FindFirstChild("HumanoidRootPart")
if human and humanoidRootPart and v ~= script.Parent then
if (humanoidRootPart.Position - humRootPart.Position).magnitude < distance then
distance = (humanoidRootPart.Position - humRootPart.Position).magnitude
target = humanoidRootPart
end
end
end
return target, distance
end