How can I use Region3 to capture bricks?

I have no clue how Region3 works, but I know it is what I need.

At the moment, there is a system for a game I am developing that I would like to set up. The concept of this system is that a user places another user, themselves or an item into the input slot. The item then comes out in the output slot, altered or the same.

At the moment, I have two “regions” set up that determine the input and output, red and green.

image

My main problem/question is how am I able to detect parts when they are “inside the blocks”?

  • I’ve used Touched, and it is a very ugly method for handling this kind of system
  • I’ve used Region3, but the method I have is awful and doesn’t support rotated blocks

Ideally I’d like to learn a bit about Region3 on top of getting a solution for this. I’ve tried everything I possibly can to no avail.

1 Like

What does ugly mean? Does it miss parts?

No. I don’t want to use touched because I have to drop tools in there via CFrame and Touched won’t capture them unless I make their CFrame touch the brick first before being properly placed. The purpose of this is to capture all the bricks that are within either region and act upon them from there.

Egomoose made a nice tutorial on the wiki regarding rotated region3’s.

The wiki article: Documentation - Roblox Creator Hub
His rotated region3 module: https://www.roblox.com/library/434885049/Rotated-region3

3 Likes

If I’m wrong please correct me but I think Part:GetTouchingParts() works this way.

It only works with cancollide-true parts, but using collision groups you could get it working.

I refuse to use any kind of touch(ing/ed) method. That’s not what I want to use and I don’t like using it.

I can’t vouch for how reliable gettouchingparts is but a major downside is cancollide false parts will be ignored.

In your particular case, I would highly recommend instead raycasting from the HumanoidRootPart downwards.

Using any Region3 functions will only get you a list of potentially meaningless parts. Instead of looking for the character, have the character look for the part.

Instead of having blocks, turn them into pads that people can walk on. Afterwords, in a local script inside StarterCharacterScript, you can do the following:

local player = game.Players.LocalPlayer
repeat wait() until player.Character
local char = player.Character
local torso = char:WaitForChild("Torso")

while wait(0.5) do
    local hit = game.Workspace:FindPartOnRay(Ray.new(torso.Position, Vector3.new(0, -20, 0)), char)
    if hit then
        if hit.Name == "Pad1" then
            -- communicate with the server to see if the player is actually on the pad
            -- proceed to carry all following responsibilities to the server script
        end
    end
end

Not trying to be rude, but @RyanSch02 already linked that exact article.

1 Like

oh
Whoops…

That doesn’t solve my problem though. I’m not only aiming to capture humanoids, I have to capture parts as well, so said capturing of “meaningless parts” is important and raycasting hundreds of objects downwards is going to be extremely expensive.

How are you dragging parts? With something like the Roblox HopperBins?

Using EgoMoose’s Region3 module, you could write something like:

local Players = game:GetService("Players")
local region3 = require(game:GetService("ServerScriptService"):FindFirstChild("RotatedRegion3")) -- wherever you put the module...
local maxParts = 20
local ignore = {}
local inputPart = workspace.Part -- the part you want your region on

while wait(.5) do
	local inputRegion = region3.fromPart(inputPart) -- creates a region based on your part's size and location
	local insideInput = inputRegion:cast(ignore, maxParts) -- gets a list of parts in your region
	for _, v in pairs(insideInput) do
		if Players:GetPlayerFromCharacter(v.Parent) then
			-- it's a player
			
		else
			-- it's a part
			
		end
	end
end

Tried to make as simple as possible

6 Likes

@EchoReaper Wait a moment, how did dragging work its way here?

@B_rcode I’m not looking to loop, just need it to run whenever a button is clicked, but I can take the code apart and work from what you’ve given me. Thanks for that (and thanks to @RyanSch02 for linking the items first, just didn’t experiment with them).

How are items getting into the input? I imagine player’s aren’t hopping around on unanchored items hoping they fling into the input. Is there some sort of dragging system for items which allows them to move items into the input?

Oh.

  • Player clicks around inside the small box (input)
  • A GUI shows up that lists the tools they have
  • Player clicks a tool, the tool is removed from their backpack and has its CFrame set a little bit above the floor of the input

Why do you need to check position then? Instead of spawning the tool in the input and waiting for a Touched event or Region3 to find it’s there, why can’t you just tell the script that’s currently checking that an item has been added from the code that spawns the tool?

Because I also need to ensure that it checks for players that put themselves in there. If a player goes in but not a tool, it has to check that there’s a player there. If a tool is dropped in, it has to check that a tool is there. If both are in there, it has to check for both.

I think this might be what you need?

Hence the title of this topic, the first sentence of the OP and the second bullet of my list of problems. I specifically put those there so that I could get an answer that wasn’t a link to a Wiki page. I’ve already checked the Wiki and it doesn’t do me well to understand how to work regions.

Going to mark a previous post as the solution so the confusion dispatches. Thanks for the help though, I do appreciate it.