Basically, I posted this earlier but without alot of context so it was just all confusing,
I’m making an npc that’s able to find cover behind walls, what I need to do is make the script create a part behind a wall no matter the size, the script works on the Z axis as shown here:
with the size of the transparent wall modified:
however with the X axis:
basically, I always want the bricks facing towards the red part to always be behind the transparent wall, no matter the size of the transparent wall. How would I do this? My current script is:
local character = script.Parent
local range = 100
local target = workspace.Target
while task.wait(1) do
for i,v in pairs(workspace:GetDescendants()) do
if v.ClassName == "Part" then
if v.Parent ~= character and v ~= target then
if (character.HumanoidRootPart.Position - v.Position).Magnitude <= 100 then
if v.Name ~= "Part" then
local lookatpart = Instance.new("Part")
lookatpart.Parent = workspace
lookatpart.CFrame = v.CFrame
lookatpart.Anchored = true
lookatpart.CanCollide = false
lookatpart.Transparency = 0
lookatpart.Size = Vector3.new(1,1,2)
lookatpart.CFrame = CFrame.lookAt(lookatpart.Position, target.Position)
lookatpart.CFrame = lookatpart.CFrame:ToWorldSpace(CFrame.new(0, 0, v.Size.Z / 2 + lookatpart.Size.Z / 2))
local direction = (workspace.Target.Position - lookatpart.Position)
local cast = workspace:Raycast(lookatpart.Position,direction)
if cast.Instance == workspace.Target then
print("target found")
-- success
else
-- no cast
print("cover found")
end
end
end
end
end
end
end
-- its not finished, i really dont code like this lol ill fix it later