My best explanation is that it's taking the position and just like, Flipping it over the character as if it was an axis.
https://gyazo.com/50cebe1227a462c073e1063b61f5bcb3
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local torso = character.Torso
local walls = game.Workspace.Walls:GetChildren()
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.E then
local lowest = 20
local low
for _, wall in pairs(walls) do
local distance = (torso.Position - wall.Position).magnitude
if distance < lowest then
lowest = distance
low = wall
end
end
print(low)
if low then
-- low may not be set if the closest is further than 20 studs
local ray = Ray.new(torso.Position, (low.Position - torso.Position).unit)
local hit, position = game.Workspace:FindPartOnRay(ray)
local distance = (low.Position - torso.Position).magnitude
local rayPart = Instance.new("Part", player.Character) -------
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("Bright red")
rayPart.Transparency = 0.5
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.2, 0.2, distance)
rayPart.CFrame = CFrame.new(position,(torso.Position - low.Position)) * CFrame.new(0, 0, distance/2)
for i = 1, #walls do
walls[i].BrickColor = BrickColor.new("Smoky grey")
end
low.BrickColor = BrickColor.Green()
end
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
