How to resize part from one face at any angle and by non integers

I have a tree rotating complexly. It’s welded to a rotating sphere. I want to adjust the height of the tree. I dont want to enter how much to grow/shrink the tree, I just want to enter the final size of the tree along the y axis, and keep the base of the tree on the surface of the sphere.

part:Resize() requires the increment (1 makes it bigger by 1, not equal to 1), not final size. I found the maths to make it work, subtracting the final size by the current size i think, however the answer is usually a fraction, and the function requires integers.

Since its at weird angles i cant just move the Y cframe up/down, and im not sure how calculate what the x y and z must be at any angle.

Help?

Images:
image
Small tree meshes welded to a mesh sphere in a viewport

image
Game running, viewport audio-vizualiser running, making meshes bigger depending on the loudness of the music, on a rotating planet. Meshes are longer as expected but are growing symmetrically instead of the bottom remaining on the planet’s surface.

Could you include some pictures of what you’re trying to do? I’m a little confused by your description and I think we might be able to help better if you can show us what you want to do w/ a picture.

2 Likes

I added images now, im making a simple audio vizualiser on my main menu. Need the trees’ Y size to grow while their base remains on the planet’s surface. They are at an angle so I can’t just move them higher in the Y position.

image

With game running:

image

So are the tree meshes are made at an angle, or are the trees rotated in studio?

they are welded to the planet. The planet rotates and they get dragged along too. they were originally vertical.

The CFrame data has three vectors that can help. They are LookVector, UpVector, and RightVector. The UpVector tells you which direction the top of the model is facing - and it’s a unit vector of length one. So if you want to grow the tree by 0.5 studs, you just take the old CFrame and add 0.5 times the UpVector.

Tree.CFrame = Tree.CFrame + Tree.CFrame.UpVector*0.5

Hope that helps

1 Like

Thank you! I didn’t know about upvector, i was thinking of somehow finding it using maths and lookvector.

I used Position instead of CFrame however as CFrame takes into acount welds and brought the whole planet with it.

Final code:

local RS = game:GetService("ReplicatedStorage")

local RunS = game:GetService("RunService")

local Audio = RS.startrekything

local tree = script.Parent

local loudness

RunS.RenderStepped:Connect(function()

loudness = Audio.PlaybackLoudness

tree.Position = tree.Position + tree.CFrame.UpVector*((loudness/100+5)-script.Parent.Size.Y)*.5

script.Parent.Size = Vector3.new(2, (loudness / 100)+5, 2)

end)
2 Likes