I can’t wrap my head around how to create a system like what was shown in the video but its vital for my game. Does anyone know a way that you can recreate it in roblox? I have the original clicked position and mouse position but can’t figure out a way to place those checkpoints in that order. Thanks!
Well, you have the startPosition where you clicked, and the endPosition where the mouse is, in terms of 3d coordinates.
Then you know how many units you have to place, and the horizontal distance between units that you want to have when they are put into rows and columns.
So I would start by taking the horizontal distance between your start and end position, that tells you how many rows you will have. From there, working out how many columns you will have isn’t rocket science either.
For example you have 70 units, 10 studs between unit positions, and the horizontal distance between start and stop is 263 studs. That means you can have 26 rows, which means you have 3 columns, the last of which is not fully filled.
Then you can just start placing your units in a nested for loop. Lets take a very simple example. 10 units in a single column. Starting at the startposition, we can just add the unit vector of endPosition-startPosition * distanceBetweenUnits * numberOfThisUnit
Simplified code:
for i=1, 1 do -- columns, we have only 1 now.
for j=1, 10 do
local myVector = endPosition-startPosition
local horizontalUnitVector = Vector3.new(myVector.X, 0, myVector.Z).Unit
local myPosition = startPosition + horizontalUnitVector * 10 * j
end
end
To have multiple columns, we need the horizontal unit vector perpendicular to our first unit vector, which is just swapping the X and Z and making one of them negative. This will allow you to offset the position for each unit depending on the column it is in. I’m sure you can work it out.
Note that this doesn’t take care of the height, nor the rotation. The height I would do using raycasts to the terrain, and the rotation is probably simply a CFrame looking in the direction of the horizontal unit vector.
Hope this gives you an idea of a general approach that you might use to do this. I didn’t test it, just some ideas and examples, but I think you can work it out in such a way.
Good luck!