Creature That Only Spawns In The Dark

Okay, so I’ve been trying to think of ways to create an aggressive NPC that only spawns in the dark. Something sort of like the Minecraft system, in which mobs spawn in a certain light level. Now, I know there is no Light Level system in Roblox, but possibly something along those lines?

For a much clearer example, I’m sort of trying to recreate a Smiler, a creature from the internet myth “The Backrooms”. Basically, it attacks you if you move away too fast, and it usually is long dark corridors.

I’m wondering if there is someway of creating a creature that spawns in darkness, and will attack if the humanoid attempts to move away. Even better, if the humanoid stares at it for long enough, it’ll disappear.

You may think, “Why not just make objects in the dark areas that allow them to spawn?” Well, sometimes in the game, lights will go out. During that time, the whole map is dark. If I only had censors in certain spots, they wouldn’t be able to spawn everywhere during the black-out.

List of the Things I Want to Confirm Are Possible:

  • A creature that stares at the humanoid from the dark
  • If lights go out, the creature can spawn anywhere
  • If lights go back on, all the creatures will disappear
  • If a humanoid tries to back away, it’ll attack
  • If a humanoid stares for long enough, it’ll disappear.

Keep in mind I’m not asking for scripts or anything, I just want to know if it’s possible, and if so, where I could get started.

2 Likes

You could take the positions of the area where it would appear, or a table of the possible positions, and check if that point is in the radius of some light, you can subtract the position of the light with where it will appear and use Magnitude, if it is less or equal to the radius, cannot appear.

1 Like

I don’t have a great deal of knowledge in scripting, so could you explain this a bit more? My game uses point lights, and it uses probably close to 2k - 3k of them. Putting an induvial setting or script into each individual light isn’t gonna be possible.

You would go through it with a loop, as an example, it will return all valid positions

Code
local function GetValidPosition(Points, Lights)
	-- Points: Positions table, Lights: table of lights
	for _, Light in pairs(Lights) do
		if not Light:IsA("PointLight") then		continue		end
		if #Points == 0 then		break		end
		
		--			Get light position				--
		local LightPosition = nil
		if Light.Parent:IsA("BasePart") then
			LightPosition = Light.Parent.Position
		elseif Light.Parent:IsA("Attachment") then
			LightPosition = Light.Parent.WorldPosition
		end
		if not LightPosition then
			warn("Invalid parent")
			continue
		end
		
		--			Check				--
		for Index, Vect3:Vector3 in pairs(Points) do
			if (LightPosition - Vect3).Magnitude <= Light.Range then
				table.remove(Points, Index)
			end
		end
	end
	return Points
end
Example details

The point that is not in the light will change color

Before


After the check


it only works with PointLight and not counting if there is a wall, it requires other calculations.

Well, this is extremely helpful, but now, I do have walls and my game, but the issue is they have hollow insides. This because my game is a very large maze, and it is a mesh. I would like to find a way to only be able to spawn where players can walk.

But with this, would this cause lag if it was used on several thousand light sources?

Edit: Since I’m more of a beginner in scripting, do you think it’d be a better idea to simply make a part that appears across the whole map when the lights go out? I think it’d work the same if I did it correctly.

I’d think I’d be able to make the dark areas mapped out so that the creatures can spawn their, and when the lights go out, I can fire a event where instead of using the small spawns, it could use the large full map spawn.

Couldn’t you just detect a blackout then create an object that allows them to spawn and make it cover the entire map?

That’s what I thought of in the post above. It seems like that actually wouldn’t be too difficult, but the problem now is the AI. I suck at NPC scripting, and I’m trying to make it so it:

  • Will turn to look at you no matter where you are
  • If you are walking for more than 2 seconds, it attacks
  • If you stare at it for 3 seconds it’ll disappear

Any articles or tips I could use for that?

For 3: Here’s a video about FOV’s. You could just reverse it so it detects your FOV instead of the NPC’s

For 2: HumanoidStateType You could use HumanoidTypeState to check if they’re walking

For 1: Making NPC look at player - Roblox Studio NPC Tutorial [READ THE DESCRIPTION] - YouTube

2 Likes

This is super helpful. I’ll take a look at all this in a bit.

Awesome! I can lend you my 173 FOV detection script if you don’t wanna/don’t know how to reverse it yourself

I’ll give it a shot first, if I can’t figure it out, I’ll shoot you a DM

What i think is better, you could check the humanoid’s MoveDirection property to test if they’re walking or jumping. You basically just get the player’s Humanoid.MoveDirection property and put
if Humanoid.MoveDirection.Magnitude > Vector3.new(0,0,0) then do something. MoveDirection is a vector3 value, so it accounts for x, y and z (sideways,frontways and upwards)

1 Like