Player's field of view | Bird's eye perspective

  1. What do you want to achieve?

I’m creating a game from a bird’s eye view and I’m thinking about a player’s vision system that would only see one part of the screen and the rest would be covered with fog.

Green is what the player sees

Red what is covered

Script regarding player rotation:

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hRP = character.HumanoidRootPart

local mouse = player:GetMouse()

game:GetService("RunService").RenderStepped:Connect(function()
	character:SetPrimaryPartCFrame(CFrame.new(hRP.CFrame.Position, Vector3.new(mouse.Hit.Position.X, hRP.CFrame.Position.Y, mouse.Hit.Position.Z)))
end)
  1. What is the issue?

I have no idea how to do this.

  1. What solutions have you tried so far?

I looked for help on the developer center, but I didn’t find anything.

6 Likes

You could try using particles and lock them to the camera

4 Likes

I don’t think particles will be a very good idea

4 Likes

Only other options are multiple parts for a fade effect or changing the lighting settings

3 Likes

The issue with lighting though is that if their graphics are all the way down there’s gonna be no fog

3 Likes

At the moment I am not worried about the fog, but more about how to make such a view that would cover the place where the fog is, for example, with a black screen and only the visible place would be in front of me

3 Likes

Maybe a part that resemble fog welded to humanoidrootpart and placed behind the character?

4 Likes

If you’re comfortable with math you could probably implement a grid system and then based on the FOV calculate the points inside of the FOV triangle and make those grids invisible

3 Likes

What I would do, is make everything really dark and use a spotlight or a surface light as the vision.

3 Likes

I found a post on stack overflow: algorithm - How to determine if a point is in a 2D triangle? - Stack Overflow

3 Likes

i can write up some code to demonstrate but basically you want to use two parts, rectangles, that overlap, and position them at 45’s from the player

example:

4 Likes

you can also do this with UI (and i’d suggest it)

3 Likes

An example would be helpful because I’m not sure I’m sure what you mean

2 Likes

I can’t do it that way, because you will see the player even if it is very very dark, so I would like to make a special triangle like in the picture, to enter my own values of what should happen in them, etc.

2 Likes

You want smth like this?

4 Likes


I used particles but it just would not work on low end devices

2 Likes

That’s exactly the kind of thing you had in mind

2 Likes

That’s why I want to do away with particles, so that there is no advantage for weaker equipment

2 Likes

So here is what I did:

Create A Part with a flashlight in it. Part must be anchored and uncollidable (and invisible)

SpotLight Settings:
Angle: 120
Brightness: 20
Range: 60
Shadows: Disabled

Lighting Changed Settings:
Ambient: 0, 0, 0
Brightness: 0
EnvironmentDiffuseScale: 0
EnvironmentSpecularScale: 0
OutdoorAmbient: 0,0,0
Technology: Future

and this is the script i used

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hRP = character:WaitForChild("HumanoidRootPart")
local camera = workspace.CurrentCamera
local fl = game.ReplicatedStorage:WaitForChild("fl")
local flashlight = fl:Clone()
flashlight.Parent = hRP
camera.CameraType = Enum.CameraType.Scriptable

local mouse = player:GetMouse()

game:GetService("RunService").RenderStepped:Connect(function()
	local characterpos = character:GetPivot().Position
	character:SetPrimaryPartCFrame(CFrame.new(hRP.CFrame.Position, Vector3.new(mouse.Hit.Position.X, hRP.CFrame.Position.Y, mouse.Hit.Position.Z)))
	local Distance = math.clamp((camera.CFrame.Position - characterpos).Magnitude, 20, 20)
	camera.CFrame = CFrame.lookAt(characterpos + Vector3.new(0, Distance, 0.5), characterpos)
	flashlight.CFrame = hRP.CFrame * CFrame.new(0, 0, 2)-- offset
end)

just replace camera script if you have to.

4 Likes

As @InfiniteYield said, a solid GUI on screen Make it look liek a solid fog background with a clear triangle cut out and blurred edges between the solid and clear sections.
Put the GUI on screen and center it to the player’s Position. figure out where the player is pointing on screen and rotate the GUI.

The other option is if the camera is alway directly above the player then place a SurfaceGUI or decal on a Transparent Part with the same wedge shaped fog image. Position it in the workspace so it’s directly above the player, or even weld it to the player make it a small Part with a BlockMesh in it to make the fog extend off the screen so the edges are never visible.

2 Likes