Stretching a rotated part in one direction

I want the part to tween its size in one direction only

RIght now when I tween both side stretches instead of one

CleanShot 2023-09-02 at 14.09.28

I’ve tried messing around with sin cos setting cframe stuff but none of them works (I’m using it wrong)

This is my code

local children = workspace:GetChildren()

local TweenService = game:GetService("TweenService")

local TweenIns, TweenOuts = {}, {}

local OutVector = Vector3.new(3, 0, 0)
local InVector = Vector3.new(30, 0, 0)

local orientation = 30

for _, child in ipairs(children) do
	if child.Name == "SpawnLocation" then
		table.insert(
			TweenOuts,
			TweenService:Create(child, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {
				Size = child.Size + OutVector,
			})
		)

		table.insert(
			TweenIns,
			TweenService:Create(child, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.In), {
				Size = child.Size + InVector,
			})
		)
	end
end

while true do
	for _, t in ipairs(TweenIns) do
		t:Play()
	end

	task.wait(1)

	for _, t in ipairs(TweenOuts) do
		t:Play()
	end

	task.wait(1)
end

this is just how physics naturally work when you change the size of something; there is equal friction on both sides so the part has no forces making it slide towards one direction. to make the part forcefully move in one direction, you would need to see at every RunService.Heartbeat frame how much the part has stretched (in this direction):
image

and then teleport it accordingly so that one side doesnt move.

yes but I dont know how to calculate the new position when it’s rotated.

i remember ToObjectSpace existing for CFrames that teleports parts relative to itself so that it ignores the rotation (what you want in this case) try implementing this with CFrame manipulation and then setting the CFrame which will just teleport it without changing any rotation.

1 Like
local children = workspace:GetChildren()

local TweenService = game:GetService("TweenService")

local TweenIns, TweenOuts = {}, {}

local OutVector = Vector3.new(3, 0, 0)
local InVector = Vector3.new(30, 0, 0)

local orientation = 30

for _, child in ipairs(children) do
	if child.Name == "SpawnLocation" then
		table.insert(
			TweenOuts,
			TweenService:Create(child, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {
				Size = child.Size + OutVector,
                                Position = child.Position + OutVector,
			})
		)

		table.insert(
			TweenIns,
			TweenService:Create(child, TweenInfo.new(1, Enum.EasingStyle.Quart, Enum.EasingDirection.In), {
				Size = child.Size + InVector,
                                Position = child.Position + InVector,
			})
		)
	end
end

while true do
	for _, t in ipairs(TweenIns) do
		t:Play()
	end

	task.wait(1)

	for _, t in ipairs(TweenOuts) do
		t:Play()
	end

	task.wait(1)
end

You need to add the position argument to your code, this will forcefully move it in the direction giving if the effect that the size is changing in 1 direction.

nope, that only works on parts with orientation 0, 0, 0. rotated parts are something else. Im pretty sure you need sin cos stuff

nevermind i did it
turns out i was going in the right direction but i forgot to make the Z axis negative

3 Likes

I think you can do that with pivot points, no?

theres only pivot points for Position and Rotation, no size

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.