#Trying to check if the camera is looking at a specific part

5 messages · Page 1 of 1 (latest)

fickle quiver
#
local Start = Vector3.zero
local End = Vector3.one
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {}
local part = workspace:Raycast(Start, End,  params)
if not part then
    return
else
    if part.Instance.Name == "Checkpart" then
        local CheckP = part.Instance
        CheckP.Color = Color3.fromRGB(255, 0, 0)
    else
        workspace.SCPDeadly.SCP096.Checkpart.Color = Color3.new(0, 255, 0)
    end
end
stone igloo
# fickle quiver ```lua local Start = Vector3.zero local End = Vector3.one local params = Raycast...

https://create.roblox.com/docs/workspace/raycasting
you can add collision group too, here is the link https://create.roblox.com/docs/reference/engine/classes/PhysicsService

local function isLookingAt(cam: Camera, what: Instance): boolean
  -- local rayParams = RaycastParams.new()
  -- rayParams.CollisionGroup = "checkingPart"
  local rayOrigin = cam.Position
  local rayDirection = cam.CFrame.LookVector
  local raycastResult = workspace:Raycast(rayOrigin, rayDirection, --[[ rayParams ]])

  if (not raycastResult) then
    return false
  end
  return raycastResult.Instance == what
end

maybe something like this could work (no guarantee)

Raycasting allows you to detect collisions and determine the position of objects.

Class.PhysicsService primarily contains methods for working with collision
groups
which define whether a set of parts may or may not collide with parts
in other collision groups. You can register a collision group through
Class.PhysicsService:RegisterCollisionGroup()|RegisterCollisionGroup() and
assign parts to it by setting those parts'...

fickle quiver
# stone igloo https://create.roblox.com/docs/workspace/raycasting you can add collision group ...
local function isLookingAt(cam: Camera, what: Instance): boolean
    -- local rayParams = RaycastParams.new()
    -- rayParams.CollisionGroup = "checkingPart"
    local rayOrigin = cam.Position
    local rayDirection = cam.CFrame.LookVector
    local params = RaycastParams.new()
    raycastResult = workspace:Raycast(rayOrigin, rayDirection, params)

    if (not raycastResult) then
        return false
    end
    return raycastResult.Instance.Name end
if raycastResult then
    if raycastResult.Instance.Name == "Checkpart" then
        print("true")
    else
        print("false")
    end
end
#

thats what i came up with

#

is it supposed to be local or