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

How do i change the position of Region3?

Asked by
Sorukan 240 Moderation Voter
5 years ago

I'm unsure how region3 works, i've done some testing by plugging in random values inside the two Vector3 values and they keep giving me weird results. I figured out that the size of the region is depended on the difference between the second Vector3 value and the first Vector3 value. I still don't know how to set it's position tho, i don't know where to even begin. Any help would be appreciated.

1 answer

Log in to vote
2
Answered by
clc02 553 Moderation Voter
5 years ago

The easiest way to understand Region3s is to go to your desktop, click on one spot on your screen and drag your cursor away. Note how the selection box starts at the corner you clicked, and expands until it hits where your cursor is at the opposite side of the box.

Region3s behave the same way, except they add another dimension and become 3d.

The first vector3 is the same as where you started clicking, the second vector3 is where you dragged your mouse. So if you wanted to find something in a box around 0,0,0 you'd go a little down left and back for the starting position, and a little up right and forward for the ending position, like Region3.new(Vector3.new(-100, -20, - 100), Vector3.new(100, 20, 100))

This would give a 200x40x200 box, with the center around 0,0,0.

You can get the center of a region 3 by adding the components (X & X, Y&Y, Z&Z) of the two Vector3's, and dividing by two. So 100, 10, 10 and 200, 20, 20 would give you a center of 150 ( (200+100)/2) 15 ((10+20)/2, and 15 ((10+20)/2

You can find the size like you already found out by figuring the difference between the two Vector3 components. In the above it would be 100 x 10 x 10.

0
Note, if you're using this to work with terrain there's a lot of other rules you need to observe with Region3s, both vectors components must be a multiple of 4, such as -4, 0, 4, 8... 200 etc. You can do this with the ExpandToGrid method of Region3's clc02 553 — 5y
Ad

Answer this question