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

How do i make a solid ray reflect of objects at 90 degrees?

Asked by 8 years ago

Hello i've been at this for a while now to little success. I want to have a raycast hit a block and reflect of it at 90 degrees. Below is the current mess of code i've come up with but it does not work as intended.

local function createBeam(part, point, surfacePoint)
    print(part.Position)
    if surfacePoint then
        print(surfacePoint)
          ray = Ray.new(point, surfacePoint * Vector3.new(1000,1000,1000))
    else
        print("no sp")
          ray = Ray.new(point, part.CFrame.lookVector * Vector3.new(1000,1000,1000))
    end
    local newPart, newPoint, newSurfacePoint = workspace:FindPartOnRay(ray)

    local beam = Instance.new("Part", workspace:WaitForChild("Beams"))
    beam.BrickColor = BrickColor.new("Bright red")
    beam.FormFactor = "Custom"
    beam.Material = "Neon"
    beam.Transparency = 0.25
    beam.Anchored = true
    beam.Locked = true
    beam.CanCollide = false

    local distance = (point - newPoint).magnitude
    beam.Size = Vector3.new(0.3, 0.3, distance)
    beam.CFrame = CFrame.new(point, newPoint) * CFrame.new(0, 0, -distance / 2)

    if newPart then
        wait(0.5)
        createBeam(newPart, newPoint, newSurfacePoint)
    else
        print("Laser end")
    end
    wait(0.5)
end

1 answer

Log in to vote
1
Answered by 8 years ago

I can't help you with this one but the user Egomoose wrote an article that might interest you. http://wiki.roblox.com/index.php?title=Dot_product

Ad

Answer this question