Getting coordinates based on size?

So I’m attempting to get the coordiantes of the xmin, xmax, zmin and zmax of a model’s bounding box. Since none of the models have primary parts I am able to get the model’s axis aligned bounding boxes. Model:GetBoundingBox returns a Tuple, and I was able to dissect the size (a Vector3) of the bounding box. However this doesn’t help me find out the position, in the Euclidian space, of the object’s corners. Anyone know how I can do this?

1 Like

minX = X - (SizeX / 2)
maxX = X + (SizeX / 2)

you would do the same for X, Y and Z


its probably best to look into Surface Normals for this sort of thing though.

or something like this I suppose.

part.CFrame.rightVector --one stud to the right of the part

so you would do

part.CFrame.rightVector-1 --max X
1 Like

Not even joking that thought dawned on me right before I saw this

Thanks for the reply!

The purpose of what I’m doing is this;
Since my game has a large map I’m dividing the map into grids of 100x100 and determining if an object is inside of a 100x100 grid, or if it inhabits multiple 100x100 grids (if it were sitting on the border between two grids). I then need to find a way to save the object’s grid data and make sure to pull it out of storage when the player is in the grid adjacent to the grid the object is in. Please do correct me if I’m wrong but do I need surface normals for this kind of algorithm, because I’m not quite sure I do?

actually for something that is “grid based” you’ll probably just want to ROUND your coordinates.

so lets say the object is at (2.3, 0, 2.5)

you would round this to the closest multiple of your GridCellSize (which is usually 4)

function roundPos(pos,m)
    --round X to closest multiple of m
    local x = math.floor(pos.X/m+0.5)*m
    --round Y to closest multiple of m
    local y = math.floor(pos.Y/m+0.5)*m
    ---round Z to closest multiple of m
    local z = math.floor(pos.Z/m+0.5)*m
    --return new position
    return Vector3.new(x,y,z)
end

you can use the function like so

--move the object to a tile position
object.Position = roundPos(object.Position, 4)

this would round the location to (4,0,4) and then you can use the TilePosition to see if its within a certain grid cell. (or if its in the whole grid in general)


EDIT: there is tons of ways to go about this, people even use Region3 to handle this sort of thing. (idk how well it’ll work for placement systems though)

Yeah, that’s what I’ve been up to actually. The issue now is just saving the data into tables and pulling it out when I want to. I only want this script to run once at the beginning of the server and then the clients can interpret the position data via local loading scripts.

if you decide to use the rounding technique then you can just save the rounded positions
(AKA the “Tile Positions”) in string format.

So once you got Tiles figured out, you can then make min/max values for the TILES

minTileX = 0
maxTileX = 25 --100 / 4