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

[Solved] How to detect if something is in the way?

Asked by 8 years ago
Edited 8 years ago

I'm remaking an old mining game I made just for fun, and I decided to reduce lag by generating parts as you mine instead of having a billion preset parts. However, there was quite the flaw in my logic when I found that the block would go through the baseplate and cause all sorts of havoc. So I figured that I should simply just make the script not generate a block when it detects something in the way would solve all of my problems. Unfortunately, I don't know how to do that... How would I go detecting if an object was in the way?

EDIT:

sayhism1's answer did help, unfortunately, it seems like the Region3s are ignoring everything. Another problem I found was you could mine a block, but it generates in your direction. I attempted a fix, but you can exploit this glitch by going to a corner and then mining.

3 answers

Log in to vote
1
Answered by 8 years ago

You can use Region3:FindPartsInRegion3() to get a list of all the items inside a specified area. Here's an example (modified from the wiki page http://wiki.roblox.com/index.php?title=API:Class/Workspace/FindPartsInRegion3)

local Point1 = corner1 -- Position of the corner of the brick you are adding
local Point2 = corner2 -- Position of the opposite corner of the brick you are adding
--This is how you must define a Region3. Because it is a bit weird, you have to take the smallest amounts as the first argument, and the larger amounts as the second argument, so you have to use math.min and math.max
local Region = Region3.new(
    Vector3.new(
        math.min(Point1.X, Point2.X),
        math.min(Point1Y, Point2.Y),
        math.min(Point1.Z, Point2.Z)
    ),
    Vector3.new(
        math.max(Point1.X, Point2.X),
        math.max(Point1.Y, Point2.Y),
        math.max(Point1.Z, Point2.Z)
    )
)
for _,Part in pairs(game.Workspace:FindPartsInRegion3(Region,nil,100)) do
  print(Part.Name) --This will print the name of every part found inside the region
end

Then you can just check #game.Workspace:FindPartsInRegion3() == 0 and execute your block spawning code.

0
Yeah, I had the same idea. I'll give it a shot if my raycast idea doesn't work lightpower26 399 — 8y
0
I'm not sure why, but it seems to be ignoring everything. I added a bit of code that shows how many parts are in the Region3 and it keeps on saying 0 lightpower26 399 — 8y
0
Hmm... Are you sure you are using the right coordinates for Vector3? sayhisam1 48 — 8y
Ad
Log in to vote
0
Answered by
crut24 50
8 years ago

Instead of generating the whole mine you can make a script (like the one i made here https://www.roblox.com/games/432944637/SBD-Studios-Place-Number-4) that generates the mine are you mine. This works better and its more responsive. Goodluck!

0
This is exactly what I was trying to do... Generate the mine as you mine. lightpower26 399 — 8y
0
It is really easy to make, i made it in 15 minutes crut24 50 — 8y
Log in to vote
0
Answered by 8 years ago

I found the answer to my problem after hours of thinking. After you mine a block, the pickaxe sends the server a message asking to check to see if it needs to generate more blocks. Like so: game.ReplicatedStorage.CheckGeneration:FireServer()

Once the server receives this message, It then checks to see if the player is getting to close to the "abyss." If the player is, then it generates a new layer of blocks. Just like this

I would add in layering for the X and Z axis, but for now, it'll do. Thanks for the help/ideas guys!

0
Actually there is no need for the layer generation, PM me and i'll give you details about how it works crut24 50 — 8y

Answer this question