How can I use Region3 to capture bricks?

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: http://wiki.roblox.com/index.php?title=User:EgoMoose/Articles/Rotated_region3
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?

http://wiki.roblox.com/index.php?title=API:Class/Workspace/FindPartsInRegion3

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.

What do you already understand? That way I’m able to see what you do/don’t understand.
Do you not understand with a Region3 is? Do you know what it is but not how to use it? I’ll gladly help but I don’t know where you get stuck.

  • I understand what a Region3s is, I just don’t know how to work it properly
  • I know how to create Region3s and call FindPartsInRegion3

My main problem is getting Region3s to be able to remain the same regardless of how I rotate it.

It’s alright though, I’ve marked a solution.