Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Object Not Being Detected When In Camera's Field of View, Why?

Asked by 3 years ago
Edited 3 years ago

I've been working on a little project that has a little event where a object, when in the player's fov (or the camera's): it simply disappears. I used the old raycasting method to achieve this; however, I sort of found out that the old method has been deprecated (plus the old method started experiencing some issues). Anyway, I'm still new to the updated raycasting and I would like to know why the object is rarely being detected.

Issue (notice the output): https://i.gyazo.com/ccf8d1f9e2cc838c22ecf6f99bdf32bf.gif

Object in workspace: https://i.gyazo.com/b53e37f8f49a719b4d33339d4488e306.png

Test Code:

local Player = game:GetService("Players").LocalPlayer
local Worskspace = game:GetService("Workspace")
local Camera = Worskspace.CurrentCamera
local RunServ = game:GetService("RunService")
function RayObject(Object)
    local Unit = (Object.Position-Camera.CFrame.Position).Unit
    local DotProduct = Unit:Dot(Camera.CFrame.LookVector)
    local ObjectParent = Object.Parent
    local RayCastParamsF = RaycastParams.new()
    local RayResult = Worskspace:Raycast(Camera.CFrame.Position, Unit*900, RayCastParamsF)
    if RayResult then
        if DotProduct > .63 and RayResult.Instance:IsDescendantOf(ObjectParent)  then
            return true
        end
    end
end

RunServ.Heartbeat:Connect(function()
    local CanSee = RayObject(Worskspace.TestObjectModel.TestObject)
    print(CanSee) --will either print "nil" or "true"
end)
0
I don't know what to say; it works just fine for me. Sorry. appxritixn 2235 — 3y

Answer this question