Part rotates when tweening CFrame

so basically i want this beam effect to resize itself and make it longer with tweening, of course it doesnt look right because i need to tween its position as well

		shot.Inside.Orientation += Vector3.new(0,90,0)
		shot.Outside.Orientation += Vector3.new(0,90,0)
		
		shot.Inside.Size = Vector3.new(0.773, 0.276, 0.46)
		shot.Outside.Size = Vector3.new(0.934, 0.566, 0.83)
		
		at(shot.Inside, 0.3, "Quad", "Out", {CFrame = hrp.CFrame*CFrame.new(0,0,-35)*shot.Inside.CFrame.Rotation})
		at(shot.Outside, 0.3, "Quad", "Out", {CFrame = hrp.CFrame*CFrame.new(0,0,-35)*shot.Inside.CFrame.Rotation})
		
		at(shot.Inside, 0.3, "Quad", "Out", {Size = Vector3.new(65, 0.1, 0.15)})
		at(shot.Outside, 0.3, "Quad", "Out", {Size = Vector3.new(70, 0.2, 0.35)})

and this is what the script gives me:
https://gyazo.com/8f3ea92ad2ee25997805c86c09c4db2c

i’ve searched the developer forums and none of the solutions have fixed it, can someone help me?

The part is rotating because the starting rotation and the end rotation aren’t the same, so it has to rotate a little bit.

OK, so the part is being moved from an unknown position (probably HumanoidRootPart.CFrame times that 90° rotation), to 35 studs forward of the character.
By that point, the part is already rotated to face the correct way, so that shot.Inside.CFrame.Rotation is double-rotating the part.
It’s rotating the part by both the 90° rotation (this is ok) and by the character’s own rotation (not ok).
If you’re facing the correct direction, then your own code will work fine because your character will have the default rotation, so to speak.

Well first of all, don’t do this!

		shot.Inside.Orientation += Vector3.new(0,90,0)
		shot.Outside.Orientation += Vector3.new(0,90,0)

Do not change Orientation in scripts. It’s a trap! Orientation will kick your dog and spoil the milk in your fridge. It confuses newbies into doing the wrong thing and getting stuck.
Instead, rotate with a CFrame that’s just a 90° rotation.

		local rotation = CFrame.Angles(0, math.rad(90), 0) -- Multiply a CFrame with this to yaw it 90°
		
		shot.Inside.CFrame *= rotation
		shot.Outside.CFrame *= rotation
		
		-- Instead of rotating by shot.Inside.CFrame.Rotation, which is 90° times the character's rotation, just rotate by 90° and nothing else 
		at(shot.Inside, 0.3, "Quad", "Out", {CFrame = hrp.CFrame*CFrame.new(0,0,-35) * rotation})
		at(shot.Outside, 0.3, "Quad", "Out", {CFrame = hrp.CFrame*CFrame.new(0,0,-35) * rotation})

This should also work because it’s retaining the shot’s rotation, but simply moving its position forward.

		at(shot.Inside, 0.3, "Quad", "Out", {Position = hrp.Position + hrp.CFrame.LookVector * -35})
		at(shot.Outside, 0.3, "Quad", "Out", {Position = hrp.Position + hrp.CFrame.LookVector * -35})
2 Likes

The part rotates when tweening the CFrame because CFrame’s have a rotation matrix and the tween tries to make it align to the given matrix.

Your parts CFrame:

172, 128, 121, 0.3472, 0.46915, 0.32672, 0.71272, 0.12585, 0.85722, 0.24672, 0.65423, 0.12612

The CFrame you tried giving it:

24, 64, 96, 1, 0, 0, 0, 1, 0, 0, 0, 1

Lets go over each component of the CFrame.

172, 128, 121 -- Position | Vector3
0.3472, 0.46915, 0.32672 -- XVector rotation matrix (normalized value) | Vector3
0.71272, 0.12585, 0.85722 -- YVector rotation matrix (normalized value) | Vector3
0.24672, 0.65423, 0.12612 -- ZVector rotation matrix (normalized value) | Vector3

CFrame’s have a property that lets you access just the rotation matrix and has a function CFrame:ToOrientation() that converts the rotation matrix to radians which can then be converted to degrees using the math.deg function and back to radians using the math.rad function.

In order to access the values returned by :ToOrientation() you must variablize them via this method:

local cf = CFrame.new(
   172, 128, 121,
   0.3472, 0.46915, 0.32672,
   0.71272, 0.12585, 0.85722,
   0.24672, 0.65423, 0.12612
)
local x, y, z = cf:ToOrientation()
print(math.deg(x), math.deg(y), math.deg(z)) -- convert to degrees

--> -59.00586080576758, 68.89248449728017, 79.98610506797156

More on CFrame’s here.

1 Like

thank you! i had no idea how to work with positions yet so i resorted to using CFrames instead.