Resize part based on start and end location

I’m trying to create a floor system, where you can click and drag floor. However, I’m having issues with it. Pos1 is the CFrame of the part at the start, Pos2 is the Cframe where the mouse is. The starting point of the part should always exist tho. As you can see, it sometimes goes off the grid, and the starting point disappears.


It needs to function exactly like this:

So pretty much pivots around the starting spot

local Difference = Pos2.Position - Pos1.Position
Floor1.Position = ((Pos1.Position + Pos2.Position) / 2) + Vector3.new(Constants.GRID_SIZE / 2, 0, Constants.GRID_SIZE / 2)
Floor1.Size = Vector3.new(
	math.clamp(math.abs(Difference.X), Constants.GRID_SIZE, math.huge),
	Floor1.Size.Y,
	math.clamp(math.abs(Difference.Z), Constants.GRID_SIZE, math.huge)
)

I think it’s the fact that you have both parts of the Floor1.Position (Pos and GRID_SIZE) divided by 2.
Take the /2 out of one, then the other to see how it affects your placement.

Removing them causes this
ezgif.com-gif-maker (52)

Did you just remove the /2 from only one of the values at a time?

Yes, neither of which got me any closer to what I’m after, made it even worse :confused:

So where are you calculating the the actual start Position? That’s what seems to be placed in half step increments.

The start pos is the part you seem before i click and drag. The square. It’s already locked to the grid correctly, so theres nothing wrong with the start and end pos i getting

Managed to figure it out:

local Difference = Pos2.Position - Pos1.Position

Floor1.Position = ((Pos1.Position + Pos2.Position) / 2)
Floor1.Size = Vector3.new(
	math.abs(Difference.X) + Constants.GRID_SIZE,
	Floor1.Size.Y,
	math.abs(Difference.Z) + Constants.GRID_SIZE
)
1 Like