Hello! I am making an advanced ai right now, and my raycast function to check if there is a direct line to the player is not working. The error says, and I quote, “Unable to cast Instance to Vector3”. I do not understand what this means? I mean, at the current moment, I’m following this part off of a tutorial, and the tutorial uses old raycasting. IE: local hit, position
stuff like that. I converted it into modern raycasting, but thats not working. Edit: The code in the modern raycast is the exact code as shown in the deprecated one, however this modern version seems to not work.
**Edited code**
local r_params = RaycastParams.new()
r_params.FilterType = Enum.RaycastFilterType.Blacklist
r_params.FilterDescendantsInstances = {rig}
local raycast_result = workspace:Raycast(human_root, (target.Position - human_root.Position).Unit * 40, r_params)
**Unedited code**
--//Checking the sight of the ai to see if there is a player
local function raycast_sight(target)
--raycasting
local r_params = RaycastParams.new()
r_params.FilterType = Enum.RaycastFilterType.Blacklist
r_params.FilterDescendantsInstances = {rig}
local raycast_result = workspace:Raycast(human_root, (target.Position - human_root.Position).Unit * 40, r_params)
if raycast_result then
local instance = raycast_result.Instance
--checking if its a model
if instance:IsDescendantOf(target.Parent) and math.abs(raycast_result.Position.Y - human_root.Position.Y) < 3 then --if the instance is a similar height to the AI
print("target_spotted")
return true
end
end
return false
end
Any help will be appreciated