Increase size of parts via dragging in game

I’m trying to create something like what the sims has with floor placement.

So basically, a floor part is made, and it follows the mouse, when the player click, the floor part stays where it is, and is extended in either direction depending which way the player drags their mouse.

This is what I have atm:

-- RenderPosition
object.CFrame = CFrame.new(Round(MouseClampedP - Vector3.new(object.Size.X / 2, 0, object.Size.Z / 2), 5, playersPlot.Base.Position.Y + (object.Size.Y / 2)))	


So the part is being centered on the grid, instead of being inside each grid box (which is 5 stud squares, same size as the floor part)

And then from here I’m not sure what to do. I don’t know to increase it’s size like how I want it. Problem with just going part.Size is it would increase in size from the centre, instead of the edge
Video example

2 Likes

This is me just thinking off the top of my head,

Couldn’t you get the starting vector and the ending vector, get the distance from the two (that’d be the size of the floor) as well as the center of the two and size it accordingly? I could be wrong here.

Sounds interesting. Found a function, Resize, which could do the trick. Never used it before, so :man_shrugging:

RenderStepped = RunService.RenderStepped:Connect(function()
		RenderPosition(PlayersPlot, mouse.Hit.p, Tile1, LowerX, UpperX, LowerZ, UpperZ)
	end)
	
	Click = mouse.Button1Down:Connect(function()
		RenderStepped:Disconnect()
		
		local OriginalVector = Tile1.Position
		
		RenderStepped = RunService.RenderStepped:Connect(function()
			
		end)
	end)

So this is where I’m at. So when they click it stops the moving tile, gets that tiles vector. How can I get the ‘new vector’ tho? As mouse.Hit.p is a CFrame value

CFrame’s have two values, a position and a lookVector,

Vector3 CFrame.Position
The 3D position of the CFrame

CFrame.Position(mouse.Hit.p)

[attempt to call field ‘Position’ (a nil value)]

Sorry I’m useless with CFrame stuff XD

local cframe = CFrame.new(pos, lookVector)
print(cframe.Position)
RenderStepped = RunService.RenderStepped:Connect(function()
	local cframe = CFrame.new(mouse.Hit.p)
	local NewVector = cframe.Position
	print(OriginalVector, NewVector)
	Tile1.Size = Vector3.new(OriginalVector.X - NewVector.X, 0.1, OriginalVector.Y - NewVector.Y)
end)

This just made the part go skinny and long and short when I dragged the mouse around :confused:

Ignore this for a sec, relised I used .Y instead of .Z

Getting somewhere I guess. Lil awkward. Any ideas where to go from here?
com-video-to-gif

You need to position the brick in the center of the two points, not at your first point :slight_smile:

That just did the same but in the opposite direction XD

Tile1.Size = Vector3.new(NewVector.X - OriginalVector.X, 0.1, NewVector.Z - OriginalVector.Z)

Unless I misunderstood??

Update

Click = mouse.Button1Down:Connect(function()
		RenderStepped:Disconnect()
		
		local OriginalVector = Tile.Position
		
		RenderStepped = RunService.RenderStepped:Connect(function()
			local NewCFrame = CFrame.new(mouse.Hit.p)
			local NewVector = NewCFrame.Position

			Tile.Size = Round(Vector3.new(NewVector.X - OriginalVector.X, 0, NewVector.Z - OriginalVector.Z), 5, PlayersPlot.Base.Position.Y + 0.1)
		end)
	end)

com-video-to-gif%20(1)
Kinda, eh, not really but ye. If anyone’s got anymore suggestions?

Current problems

  1. Resizing is being done from the centre, instead of having the original part as the corner, like the sims
  2. Part can be made super thin (if the the original and new vector difference is < 5?? then the part should just stay how it normally would be)
  3. Part is being made fat?? As in the y axis has become larger. It should stay flat against the floor

I can’t see your video, are you sure its not just a picture?

com-video-to-gif%20(1)

Hold i have to get another copy for some reason it aint loading the gif

Nvm it doesnt wanna become a gif :confused: basically it doesn’t work. I mentioned the problems here

  1. Resizing is being done from the centre, instead of having the original part as the corner, like the sims
  2. Part can be made super thin (if the the original and new vector difference is < 5?? then the part should just stay how it normally would be)
  3. Part is being made fat?? As in the y axis has become larger. It should stay flat against the floor

I’m not entirely sure what is causing this, I’ll try and script something up myself to see if I can replicate this and or find a solution. I can’t promise it’ll be done tonight though.

1 Like

Any update??? :confused:

Still haven’t figured out a solution to this :confused:

This is what I have so far
com-video-to-gif%20(3)

RenderStepped = RunService.RenderStepped:Connect(function()
	RenderPosition(PlayersPlot, mouse.Hit.p, Tile, LowerX, UpperX, LowerZ, UpperZ)
end)
	
Click = mouse.Button1Down:Connect(function()
	RenderStepped:Disconnect()
	
	local OriginalVector = Tile.Position
		
	RenderStepped = RunService.RenderStepped:Connect(function()
		local NewCFrame = CFrame.new(mouse.Hit.p)
		local NewVector = NewCFrame.Position

        -- Here is where I resize the part
		Tile.Size = Round(Vector3.new(NewVector.X - OriginalVector.X, 0, NewVector.Z - OriginalVector.Z), 5, PlayersPlot.Base.Position.Y + 0.1)
	end)
end)

Just to reitterate, what I’m after is something like the sims floor placement
Video in case you don’t know how the floor placement works

Not worried about the triangle stuff, just after the main placement

1 Like

Hey, I was trying to do something like this. Not sure if you ever figured it out. I came across this question because I was also looking to see how to do it.

RunService:BindToRenderStep("DrawPart", Enum.RenderPriority.Input.Value, function(Step) 
	local Hit = Mouse.Hit
	local Distance = 0
	if LastHit then Distance = (LastHit.Position - Hit.Position).Magnitude end
	local Center = (LastHit.Position + Hit.Position) / 2
	local DistX = LastHit.Position.X - Hit.Position.X
	local DistZ = LastHit.Position.Z - Hit.Position.Z 
		
	Workspace.BoxSelect.CFrame = CFrame.new(Center)
	Workspace.BoxSelect.Size = Vector3.new( math.abs(DistX), 2,math.abs(DistZ) )
end)

From reading the thread

I indeed positioned a part to the center, and then set the size based on the distance from the initial click and the current mouse position.

:slight_smile:

I ended up giving up :confused: Couldn’t figure it out