Resize part toward mouse?

I’m trying to make a part “resize” towards my mouse. I’ve come pretty close, but I can’t get the last things right.

The part doesn’t go all the way to my mouse and it’s resizing in both directions when I want it to only go towards the mouse. It also doesn’t seem to work when I move the mouse to positive Vector3s? It won’t resize in the right direction if my mouse is at the bottom of the screen.

I have tried using the Resize() function to no avail-- it just seemingly endlessly resizes the part.

Code:

p.Size = Vector3.new(p.Size.X, p.Size.Y, (mouse.Hit.p - p.Position).magnitude)
p.CFrame = CFrame.new(Vector3.new(cf.p.X, .5, cf.p.Z), Vector3.new(mouse.hit.p.X, .5, mouse.hit.p.Y))

Help is appreciated :slight_smile:

2 Likes

I added some things to your code and got this result,
is this what you are trying to achieve?

1 Like

Yes, exactly! How’d you do it?

This is the code I used.

function update()
	--start is the part's cframe (outside the function)		
	local pos = mouse.Hit.p
	local distance = (start.p - pos).magnitude 
		
	if distance > 1000 then --limit distance otherwise it would get to 9999
		distance = 1000
	end
			
	p.Size = Vector3.new(p.Size.X, p.Size.Y, distance)
	p.CFrame = CFrame.new(Vector3.new(start.p.X, .5, start.p.Z), Vector3.new(pos.X, pos.Y, pos.Z)) * CFrame.new(0, 0, -distance / 2)
end

Also, I recommend changing the mouse TargetFilter to the part
:grinning:

6 Likes

It worked. Thanks!

1 Like