print(player.char.HumanoidRootPart.CFrame.Rotation.Y)
print(player.char.HumanoidRootPart.Rotation.Y)
I am a bit puzzled on the difference between these two. The first only prints zero, and the second prints the rotation.
print(player.char.HumanoidRootPart.CFrame.Rotation.Y)
print(player.char.HumanoidRootPart.Rotation.Y)
I am a bit puzzled on the difference between these two. The first only prints zero, and the second prints the rotation.
I know that CFrame.Rotation is read only, which means you cannot define it, but .Rotation is definable. I do not know why your script prints two different values though.
BasePart.Rotation gives a vector containing rotation angles around the x, y and z axes. CFrame.Rotation gives the rotation component of the CFrame. This rotation component is a CFrame and thus contains the right, up and back vector and the position. If we have a CFrame cf
, then cf.Rotation
is equal to cf - cf.Position
. CFrame.Y gives the y component of the CFrame’s position. Because the position in cf.Rotation
is the zero vector, its y component is zero.
A gross oversimplification is
.Rotation.Y shows the rotation relative to the world kind of like how .Position.Y would
while
.CFrame.Rotation.Y is a component of an object’s rotational CFrame, and CFrame describes both the Position and Orientation (AKA Rotation) (Also, CFrame can have mathametical operations applied to it!!!)
CFrame is usually more efficient to use and is useful in all sorts of applications, like pointing a brick towards another one.
So how would you recommend getting the y rotation?
BaseParts have two properties that give rotation angles. They are BasePart.Rotation and BasePart.Orientation. There’s a difference between them, though. Rotation angles are applied in xyz order while rotation angles are applied in yxz order. Also, in both cases, they are applied in local space of the part. In the case of the angle that is applied first, though, applying it in local space is equivalent to applying it in global space.
When part.Rotation == Vector3.new(60, 30, 45), it’s rotation CFrame can be achieved by first rotating the identity CFrame 60 degrees around its x axis (identity CFrame axes are the same as world axes, though), then rotating the result of the x axis rotation 30 degrees around the result’s y axis and finally rotating the result of these two rotation 45 degrees around the z axis of this result of two rotations. So basically, in studio, you can do this by setting rotation the rotation tools’s rotation mode to local (CTRL + L is used to toggle this, idk what it’s actually called as this also toggles movement tool between local and global) and then applying the three rotations mentioned for a part whose initial rotation is Vector.new(0, 0, 0). The equation below approximately holds.
part.CFrame.Rotation == CFrame.Angles(part.Rotation.X, 0, 0) * CFrame.Angles(0, part.Rotation.Y, 0) * CFrame.Angles(0, 0, part.Rotation.Z)
Here’s a similar equation for BasePart.Orientation. As you can see, the y axis rotation CFrame is now written before the x axis rotation CFrame.
part.CFrame.Rotation == CFrame.Angles(0, part.Orientation.Y, 0) * CFrame.Angles(part.Orientation.X, 0, 0) * CFrame.Angles(0, 0, part.Orientation.Z)
Using orientation.Y is probably a better idea than using Rotation.Y. For example, if you have an initially non-rotated part and you rotate it 180 degrees around the world y axis, its orientation will be (0, 180, 0) but its rotation will be (180, 0, 180). Both describe the same rotation but, as mentioned before, BasePart.Rotation describes a rotation applied in xyz order and BasePart.Orientation describes a rotation applied in yxz order. I believe you’d like to get the value 180 for y rotation in this case instead of 0 so Orientation would be better.