I am making a top-down game where the camera is a few studs behind the top of the player.
How would I make any object between the camera and the player become half transparent? (So the player could see their character).
I am making a top-down game where the camera is a few studs behind the top of the player.
Add this function to your code and run it to check if a part is blocking cam.
local oldPart = nil
local function checkIfPartInfront(cam, hrp) -------------- cam is the camera of the player and hrp is the humanoidrootpart of the player\
local dir = (cam.CFrame.Position - hrp.Position).Unit * (cam.CFrame.Position - hrp.Position).Magnitude
local result = workspace:Raycast(cam.CFrame.Position, dir)
if result then
local instance = result.Instance
if instance:IsDescendantOf(hrp.Parent) then
print("No part is blocking cam")
oldPart.Transparency = 0
oldPart = nil
else
print("part is blocking cam")
instance.Transparency = 0.7 -------- adjust this 1 is transparent 0 is not transparent
oldPart = instance
end
end
end
coroutine.wrap(function()
while wait() do
checkIfPartInfront(workspace.CurrentCamera, game.Players.LocalPlayer.Character:WaitForChild('HumanoidRootPart'))
end
end
You can use Invisicam to get the effect you want
You can find it under StarterPlayer
Yes!
I read something on the dev hub that was talking about this. It’s a really cool inbuilt feature and i’m glad that it exists!
Basically, if a part is in front of a player, it will turn the part’s transparency down so you can see the player.
This only seems to work if I comment out my top-down script. (Probably because I change the camera type to ‘scriptable’.)
It doesn’t seem to work, although there are no errors either.
You can use get parts obscuring target,
There’s some example code in the devhub
https://developer.roblox.com/en-us/api-reference/function/Camera/GetPartsObscuringTarget
Is it in a local script? Also I forgot to call the coroutine. This should do the trick:
local oldPart = nil
local function checkIfPartInfront(cam, hrp) -------------- cam is the camera of the player and hrp is the humanoidrootpart of the player\
local dir = (cam.CFrame.Position - hrp.Position).Unit * (cam.CFrame.Position - hrp.Position).Magnitude
local result = workspace:Raycast(cam.CFrame.Position, dir)
if result then
local instance = result.Instance
if instance:IsDescendantOf(hrp.Parent) then
print("No part is blocking cam")
oldPart.Transparency = 0
oldPart = nil
else
print("part is blocking cam")
instance.Transparency = 0.7 -------- adjust this 1 is transparent 0 is not transparent
oldPart = instance
end
end
end
coroutine.wrap(function()
while wait() do
checkIfPartInfront(workspace.CurrentCamera, game.Players.LocalPlayer.Character:WaitForChild('HumanoidRootPart'))
end
end()