I’m making a placement system which only allows you to place an object on valid grid squares, what I have works IF the object is not rotated.
In the following GIFs, the Blue Squares indicates the grid squares that are valid/exists (where the object wants to be places). The object in the GIFs requires 6 valid grid squares, any less & it wont move to that new position.
Assuming that we will always have 90, 180, 270 etc (assuming clockwise).
90: negate just z value
180 degrees: negate x and z values
270: negate just x value
By ‘y’ do you mean ‘z’? regardless this didnt work
My code (before hand)
local start_position = Vector3.new( -- hitboxPosition = origin point (center)
hitboxPosition.X - (hitbox.Size.X/2),
0,
hitboxPosition.Z - (hitbox.Size.Z/2)
)
for i = 1, math.round(hitbox.Size.X / self._grid) do -- for each grid it occupies
local point = start_position + Vector3.new((self._grid * i) - (self._grid/2), 0, 0)
for ii = 1, math.round(hitbox.Size.Z / self._grid) do -- for each grid it occupies
local newPoint = point + Vector3.new(0, 0, (self._grid * ii) - (self._grid/2))
local newVector = Vector3.new( -- grid cell point
math.floor(newPoint.X * 1e+3) / 1e+3,
0,
math.floor(newPoint.Z * 1e+3) / 1e+3
)
table.insert(points, newVector)
end
It the GIFs it might look like 1 model meaning 1 hitbox, but there are actually 2 hitboxes, I’m getting the grid cells for each hitbox. The entire item has a “master” hitbox which is how I’m moving the entire thing, the “sub” hitboxes need to rotate around the origin (center) of the “master” hitbox
If your code works when the object is not rotated, you should make the vector relative to the rotation of the grid. You can either do this using object space or subtracting the rotation.
That’s because you are rotating their entire position.
Instead rotate their offset from the center blue square first.
After that you can apply the position of the entire model to all squares.
The blocks have an individual offset value from the center block (these are: (0,0), (1,0), (1,-1))
then the whole section has an offset value from the origin (which is (-3,3))
First rotate the blocks individual offset, then apply the sections offset (which in this case was (-3,3))