I want to get a target from the middle of the camera, but i’m getting very weird magnitudes when I try to get it.
This is what im doing.
local Target = nil
local closestmag = math.huge
local vector = Vector2.new(workspace.CurrentCamera.ViewportSize.X / 2, workspace.CurrentCamera.ViewportSize.Y / 2)
for i,v in pairs (workspace.Players:GetChildren()) do
if v:FindFirstChild("HumanoidRootPart") and v ~= Player.Character then
local mag = (vector - Vector2.new(v.HumanoidRootPart.Position.X, v.HumanoidRootPart.Position.Y)).magnitude; print(mag)
if mag < 65 and mag < closestmag then
Target = v; closestmag = mag
end
end
When I print the mag, it comes out to be a ridiculous number like 1911. Any solutions?
Target also prints nil.
Trying this, but it gives ridiculous magnitudes, like 3000+. This is what I have
for i,v in pairs (workspace.Players:GetChildren()) do
if v:FindFirstChild("HumanoidRootPart") and v ~= Player.Character then
local worldPoint = v.HumanoidRootPart.Position
local vector, inViewport = camera:WorldToViewportPoint(worldPoint) print(vector, inViewport)
if inViewport then
local mag = (vector - v.HumanoidRootPart.Position).magnitude; print(mag)
if mag < 65 and mag < closestmag then
Target = v; closestmag = mag
end
end
end
end