Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a part grow?

So, I have a part. It gets rotated and positioned according to the players torso's position and mouse.Hit.p

laser.CFrame = CFrame.new((start+pos)/2,start) -- start is player.Character.Torso.Position
laser.CFrame = CFrame.new(laser.Position,pos)*CFrame.Angles(0,math.rad(90),0)--pos is mouse.Hit.p

That's what does all the part's CFrame. I was trying to get one end of it to stay on the player and the other end to grow.

function grow(part,dis,start)
	repeat wait(0)
		local pos = Vector3.new(part.Size.X*2,part.Size.Y,part.Size.Z*2)
		local center = (pos+start)/2
		part.CFrame = CFrame.new(Vector3.new(center.X-start.X,center.Y,center.Z-start.Z),start)
		part.CFrame = CFrame.new(part.Position,pos)*CFrame.Angles(0,math.rad(90),0)
		part.Size = part.Size +Vector3.new(1,0,0)
	until part.Size.X >= math.floor(dis)
end

I changed this function a lot. The above is the latest attempt, and it failed so hard.

If I use:

function grow(part,dis,start,pos)
	repeat wait(0)
		local center = (pos+start)/2
		part.CFrame = CFrame.new(center,start)
		part.CFrame = CFrame.new(part.Position,pos)*CFrame.Angles(0,math.rad(90),0)
		part.Size = part.Size +Vector3.new(1,0,0)
	until part.Size.X >= math.floor(dis)
end

It grows from the center, and that isn't good.

I tried this.

function grow(part,dis,start,pos)
	repeat wait(0)
		local center = (pos+start)/2
		part.CFrame = CFrame.new(center,start)
		part.CFrame = CFrame.new(part.Position,pos)*CFrame.Angles(0,math.rad(90),0)
		print(part:Resize(3,1))
	until part.Size.X >= math.floor(dis)
end

And it did the same thing!

#Any help is appreciated

4 comments

0

No output...?

0

no, it works, just not the way I want it to.

0

edited

2 answers

✓ Accepted answer

You need to offset the CFrame of the part by half of the amount you change the size to simulate it growing in a particular direction.

What I have done is create a function that stores the initial CFrame and size of the part and just adds on the appropriate amount to each of the properties at a given time point. To calculate this amount, I keep track of the elapsed time and compare it to the duration to get a value between 0 and 1. I can then multiply this by the desired end amount to get an interpolated value:

function grow(part, amount, duration)
	local initialCFrame = part.CFrame
	local initalSize = part.Size
	local elapsed = 0
	
	while elapsed < duration do
		elapsed = elapsed + wait()
		local alpha = math.min(elapsed/duration, 1)
		
		part.Size = initalSize + Vector3.new(amount*alpha, 0, 0)
		part.CFrame = initialCFrame*CFrame.new(amount*alpha/2, 0, 0)
	end
end

If you wanted it to grow on the surface of a moving object, you would have to adjust the value of the initialCFrame on each iteration of the while loop. I would also suggest using Heartbeat to make it happen every render frame if you want to do it on a moving object.

6 comments

0

It dpesn't start at the starting point.

0
0

amount is the distance between start and end right? and duration is the time it should take?

0

Fixed! I was making the part in the center of mouse.Hit.p and the start point. My issue entirely, and thank you!

0

Glad I could help :)

As far as my knowledge goes you can't resize parts from one direction, but what I can suggest is that you resize the part and move them to one direction. I'm not good at CFrameing and part positioning, so I can't make a suitable example, this is only a theory that I think it would solve your problem.

1 comment

0

Well thank you, I was hoping for some help but instead got a theory.

This discussion is preserved as it was. New answers, comments, and votes are closed.