[Solved] Multiple raycasts to check front

So, I’m trying to achieve something like that:
image

In a double for loop, e need to create 9 points towards the player, as if it were facing a plane made up of these 9 points.

But, this is what I’ve gotten so far:
image

I seems that X and Z axis are inversely proportional, and I don’t know how to “invert” it. I would appreciate your help.

[SOLUTION]
After spending some time, I managed to find the equation that “inverts” the axes.
horizontal vertical

function CheckFront(Character) -- not really raycasting...
	local RaycastPoints = {}
	local Root = Character.HumanoidRootPart
	local Origin = Root.Position + Root.CFrame.LookVector * 3
    local LV = Root.CFrame.LookVector
	for i = -1, 1 do
		if i == 0 then continue end
		for j = -1, 1 do
			if j == 0 then continue end
			
			local X = (LV.X - LV.Z) * LV.Z -- formula
			local Z = (LV.Z - LV.X) * LV.X -- formula
			local Position = Vector3.new(j * X , i, j * Z) + Origin
			
            -- for debugging purposes:
            local part = Instance.new("Part")
			part.Size = Vector3.one
			part.Anchored = true
			part.Position = Position
			part.CanCollide = false
			part.BrickColor = BrickColor.Red()
			part.Shape = Enum.PartType.Ball
			part.Parent = workspace
			Debris:AddItem(part, 3)
		end
	end
end

There’s a bug, I’ll solve it then fix the post.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.