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

Raycasting for rendering help? [UNSOLVED]

Asked by 8 years ago

I've been working on making a rendering thing for my game, as many blocks aren't needed at times unless a player is close. So I do have a module script for rendering things and deploying a script to unrender after a certain time, but I don't know what to do for the raycasting to get the blocks that need rendering.

Is there a specific way to this easily and receive blocks only up to 256 studs? Each brick is 2x2x2 if you need that. Here is a script I have but it's for a single part not many. I tried to use it to learn what to do, but I still have no clue what I need to do :/ Any help is appreciated.

local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Part = workspace.Part

local Range = 10
local Arc = 180

function RayIgnore(Part)
    if Part and Part.Parent then
        if Part.Transparency >= 1 and Part == Player.Character:findFirstChild("Head") and Part == Player.Character:findFirstChild("Torso") then
            return true
        end
    end
    return false
end

function RayCast(Start, Vec, Dist)
    local Hit, Pos = workspace:findPartOnRay(Ray.new(Start + (Vec *.1), Vec * Dist))
    if Hit ~= nil and Pos then
        local Dist2 = Dist - (Pos - Start).magnitude
        if RayIgnore(Hit) and Dist2 > 0 then
            return RayCast(Pos, Vec, Dist2)
        end
    end
    return Hit, Pos
end

function CheckSight()
    if Camera then
        local ToTargetVec = Camera.CoordinateFrame.p - Part.Position
        if ToTargetVec.magnitude < Range then
            local UnitTargetVec = ToTargetVec.unit
            if UnitTargetVec:Dot(-Camera.CoordinateFrame.lookVector.unit) > math.cos(math.rad(Arc)) then
                local Hit, Pos = RayCast(Part.Position, UnitTargetVec, Range)
                if Hit == false then
                    return true
                end
            end
        end
    end
    return false
end

while wait(.1) do
    if CheckSight then
        print("Blah")
    else
        print("Nay")
    end
end

Oh, the module is called ObjectRendering, in the ServerScriptService, the function is RenderObjects, then the argument is a list of objects. i can switch it to a single object if needed.

Here's the current game link, it just loads a single chunk for the game, I will be making the heights more intervally (Is that even a word) later on for about .25 studs. So here: www.roblox.com/games/261873684/Dungeon-Adventure

0
Or you could use Workspace.StreamingEnabled and save a lot of time. unmiss 337 — 8y
0
Really :/ legobuildermaster 220 — 8y
0
Wait no that won't work at all for me legobuildermaster 220 — 8y
0
The blocks are a max of 64 studs away. legobuildermaster 220 — 8y

Answer this question