I’m doing something that tells me if an object is in the middle of the screen but I get the title error
while wait() do
local camera = workspace.CurrentCamera.ViewportSize / 2
local worldPoint = workspace.detecciontest
---error here
local vector, onScreen = camera:WorldToScreenPoint(worldPoint.Position)
-----------------------------------------------------------------------------
local screenPoint = Vector2.new(vector.X, vector.Y)
local depth = vector.Z
print(onScreen)
end
workspace.CurrentCamera.ViewportSize *= .5
local camera = workspace.CurrentCamera
while wait() do
local worldPoint = workspace.detecciontest
local vector, onScreen = camera:WorldToScreenPoint(worldPoint.Position)
local screenPoint = Vector2.new(vector.X, vector.Y)
local depth = vector.Z
print(onScreen)
end
but i got the error= can’t set value in the 1st line
What? Never hear of that kind of errors. Anyway, just make it like that:
local camera = workspace.CurrentCamera
camera.ViewportSize *= .5
while wait() do
local worldPoint = workspace.detecciontest
local vector, onScreen = camera:WorldToScreenPoint(worldPoint.Position)
local screenPoint = Vector2.new(vector.X, vector.Y)
local depth = vector.Z
print(onScreen)
end
Or you could use the field of view to calculate this instead. You’d also want to use WorldRoot | Roblox Creator Documentation to determine if there are any part bounds extending from the position that are in the camera’s view.
local camera = workspace.CurrentCamera
while wait() do
local worldPoint = workspace.detecciontest
local vector, depth= camera:WorldToScreenPoint(worldPoint.Position)
local delta = Vector2.new(vector.X, vector.Y)-camera.ViewportSize/2
print(delta.magnitude<camera.ViewportSize.X/5)
end