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

Why is my part tweening like this?

local tService = game:GetService("TweenService")
local ship = script.Parent

local tSettings = TweenInfo.new(
	5,
	Enum.EasingStyle.Quart,
	Enum.EasingDirection.In,
	2,
	true,
	1.5
)

local partsettings = {
	Orientation = Vector3.new(0,180,0);
	Position = Vector3.new(168.907, 83.232, 113.6)
}


local tween = tService:Create(ship, tSettings, partsettings)
tween:Play()

My idea was to have the ship move and turn backwards at the same time, but the ship just moves forward, then moves backwards. Then, the ship moves forward again, but starts spinning like a maniac, forward and back. I'm new to TweenService, so does anyone know why this is happening?

1 answer

✓ Accepted answer

Your erratic rotation is because under the hood, "Orientation" isn't a property at all, it's a pair of getter and setter functions that translate the Euler angle values to the rotation matrix of a CFrame. Unfortunately, this isn't a 1-to-1 mapping: a rotation matrix has multiple valid Euler angle representations. A 180-degree turn about 1 axis is unambiguous in matrix form, but it's also the same matrix as -180 degrees around that same axis, or a combination of 180-degree turns on the other 2 axes. Basically, it's not just tweening the middle value from 0 to 180 and back, it's converting to and from a matrix and screwing up the numbers.

The way to get around this is to tween a CFrame. If your model is all welded together, it can just be the CFrame of the PrimaryPart. If you want a different center of rotation, make a new invisible part, welded to the PrimaryPart, and tween its CFrame. If the model is not welded together, AFAIK you can't easily tween it, you have to resort to an additional bit of scripting to tween some proxy item (e.g. an Attachment) and copy the CFrame to the model via SetPrimaryPartCFrame every frame while the tween is running.

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