So i have an AI that will cast a ray starting from the AIs torso and ending at a enemys torso, to detect rather there's any part between them.
How do i calculate the direction of the targets torso from the AIs torso?
The link here might help you with what you're trying to accomplish.
--script in the AI's torso local character = PLAYER --a reference to the character who's torso you're trying to detect. local dist = 30 --Distance of the ray, i.e. the distance the AI can see the player from. local ray = Ray.new(script.Parent.Position,(character.Torso.Position - script.Parent.Position).unit*dist) --A new ray, the first parameter is the start, which is the AI's torso, and the second parameter is the endpoint of the ray. The first part of the second parameter can be considered as the 3d slope, or direction the ray will travel in. The second part, dist, is how far we travel down that slope. local part,position = workspace:FindPartOnRay(ray,script.Parent.Parent,false,true) --find the first part the ray touches, ignoring any parts belonging to the AI if part:IsDescendantOf(character) then --if the part hit belongs to the character then print the character's name print("I see "..character.Name) end
I found out.
local start = script.Parent.Torso.CFrame.p local finish = target.Value.Torso.CFrame.p local ray = Ray.new(start,(finish - start).unit *50) --Casts ray local Raypart,pos = game.Workspace:FindPartOnRay(ray)