Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Raycast hitting the wrong place?

Asked by 2 years ago
wait(6)
local mathrad = 20
local function GetXZ(Angle)
    local X = math.cos(Angle) * mathrad
    local Z = math.sin(Angle) * mathrad
    return X,Z
end
local Character = game.Players.LocalPlayer.Character
for i = 1,20,1 do
    local Angle = i * (2 * math.pi / mathrad)
    local X,Z = GetXZ(Angle)
    local R = workspace:Raycast(Character.HumanoidRootPart.Position + Vector3.new(X,0,Z),Character.HumanoidRootPart.Position + Vector3.new(X,-10,Z))
    if R then
        local Part = Instance.new("Part")
        Part.Parent = workspace
        Part.Anchored = true
        Part.CFrame = CFrame.new(R.Position,R.Position,R.Normal),CFrame.Angles(math.random(-360,360),math.random(-360,360),math.random(-360,360))
        Part.Size = Vector3.new(1,1,1)
    end
end

Answer this question