Tween rotation problem

Hi,
I’m working on wall building system. But there is a problem with tweening, when the rotation of the wall is -90 then with next move it’ll change to +90 that means the wall’ll rotate 180 degrees instead of rotating only a few degrees. I tried using radians and tweening using CFrame, but it didn’t work.

video:
robloxapp-20220401-1546025.wmv (732.1 KB)

my script:

		local RecalculatedPos1 = module:CalculateModelPosition(Point1)
		local RecalculatedPos2 = module:CalculateModelPosition(Point2)

		local MiddlePositionX = (RecalculatedPos1.X+RecalculatedPos2.X)/2
		local MiddlePositionZ = (RecalculatedPos1.Z+RecalculatedPos2.Z)/2
		local MiddlePositionY = RecalculatedPos1.Y+((OtherData["Height"]*module.ItemInteracting.CurrentYGridSize)/2)
		local TriangleSideA   = RecalculatedPos2.X - RecalculatedPos1.X
		local TriangleSideB   = RecalculatedPos1.Z - RecalculatedPos2.Z
		local TriangleSideC   = math.sqrt((TriangleSideA * TriangleSideA) + (TriangleSideB * TriangleSideB)) --Calculate triangle side C by Pythagorean theorem, SideC = MiddlePart size between Point1 and Point2
		local TriangleAngle   = math.deg(math.atan(TriangleSideB/TriangleSideA)) --Calculate isosceles triange angle in degrees, Triange angle Aplha = Triangle angle Beta, Triangle angle Delta is counting by size of side A and side B

		if module.Settings.MaxPlaneVerticalScalingLenght < TriangleSideC then
			TriangleSideC = module.Settings.MaxPlaneVerticalScalingLenght
		end

		local MiddleSize     = Vector3.new(TriangleSideC,OtherData["Height"]*module.ItemInteracting.CurrentYGridSize,0.5)
		local StartPosition  = RecalculatedPos1
		local EndPosition    = Vector3.new(RecalculatedPos2.X,RecalculatedPos1.Y,RecalculatedPos2.Z)
		local MiddleRotation = Vector3.new(0,TriangleAngle,0)
		local MiddlePosition = Vector3.new(MiddlePositionX,MiddlePositionY,MiddlePositionZ)
		
		print(MiddleRotation.Y)
		
		if (ScalingPart.Position - MiddlePosition).Magnitude > module.Settings.MaxPlaneVerticalScalingLenght then --Set tween goal before tween started if middle part position is too far from goal position
			ScalingPart.Position = MiddlePosition
			ScalingPart.Size = MiddleSize
			return
		end

		if TweenInstance2 then
			TweenInstance2:Cancel()
		end

		local TweenGoal = {	
			Position = MiddlePosition,
			Size = MiddleSize,
			Orientation = MiddleRotation
		}
		
		TweenInstance2 = TweenService:Create(ScalingPart, module.Settings.TweenSettings, TweenGoal)
		TweenInstance2:Play()

Thank you for any help!

Here’s the video as MP4 so you don’t have to downland it.

A quick and dirty solution I can currently think off is to add a tiny random amount of radians/degrees to the rotation of the wall so the engine actually knows what direction it actually has to rotate to.

Talking about like 0.1 radians/degrees or so.

2 Likes

That won’t change anything, because one number is in minus and one in plus (It’s hard to explain), the rotation is -90 and then +90 which means the difference is 180 right? But this works only in one direction. So it’ll never be considered by the tween to rotate in the opposite direction. I tried it to be sure that I’m right and there was no change. But good idea!

Have you tried translating it to a local space first, then performing the calculation and then translating back to world space?

By translating to local space you can make all coordinates positive and smaller.

I tried it, and I don’t see any difference.
Am I doing something wrong?

ScalingPart.CFrame:VectorToObjectSpace(Vector3.new(0,TriangleAngle,0))