Hello devs!
If you know or ever played the left 4 dead series, You could know that the game contains a special AI that ain’t a survivor neither a zombie but a director.
I’ve tried getting hitboxes to disable spawns if not being seen but it didn’t work.
I’m new to raycast so it will be a big problem.
So… Any ideas to make it actually work?
1 Like
Definitely possible. If you’re having specific issues like needing help with how to do the raycasts, please post some details as a comment or even a separate post. If you do this, it’s often helpful to post the code you have even if it doesn’t work.
Not sure what that means.
If explaining something is hard, it’s often helpful to draw a diagram.
If you look up how does the l4d2 director AI works, you will see what i mean.
I don’t want any code, I just want some examples and ideas to i merge so i can create a fully functional director ai.
1 Like
Alright, seems like it handles enemy spawning like this:
the Infected are spawned out of sight from the Survivors, and are de-spawned after the Survivors move out of range
- The Director | Left 4 Dead Wiki | Fandom
There isn’t really a perfect way of checking visibility from a camera to a volume (e.g. a Part representing a spawning area for enemies). But a decent first approximation is to check line of sight (LoS) from the center of the player’s Camera to a potential spawn point.
This should almost certainly be done on the server, so since cameras don’t replicate to the server you’ll have to check LoS from the heads or something. A function for doing that could look like this:
local lineOfSightRaycastParams = RaycastParams.new()
function hasLineOfSight(pointA, pointB)
local result = game.Workspace:Raycast(pointA, pointB - pointA, lineOfSightRaycastParams)
return result == nil
end
function isSpawnPointInSightOfAnyPlayer(spawnPoint)
for _, player in pairs(game.Players:GetPlayers()) do
--Dead or otherwise unspawned players have no character
-- TODO: Handle these cases so
local head = player.Character and player.Character:FindFirstChild("Head")
if not head then continue end
if hasLineOfSight(head.Position, spawnPoint) then
return true
end
end
return false
end
function isSpawnPointAvailable(spawnPoint)
return not isSpawnPointinSightOfAnyPlayer(spawnPoint)
--There will probably be other conditions for spawning somewhere
end
Moving on from that, you might want to add some more logic for prioritizing spawn points that are more desirable than others, e.g. in front of the players in terms of progress in the level and not behind them where they’ve already been and are unlikely to even meet them. Feel free to make separate posts if you get stuck on something specific, or just comment here if you want.
Hope this helps!
1 Like
I will check solution if it helped when roblox gets back up because my studio really don’t wanna load.
1 Like
My output is getting a attempt to perform arithmetic (sub) on Instance and Vector3.
in line 4
spawnPoint
should be a point in space, so a Vector3. Not a Part or a SpawnLocation.