In geometry, a position is a vector that represents a location of a point in relation to an origin. Positions are often coupled with rotational data and are used to determine the location and orientation of objects. A position within a place is represented by a few data types: in 3D space, position (and rotation as well) is represented by two data types; CFrame and Vector3 (a part's CFrame, Position and Rotation property, for example), while in 2D space, it is represented by UDim, UDim2 and Vector2 (a GUI element's Position property, for example).
3D[]
Positions and orientations within a place is represented by both CFrame and Vector3 properties, where positions are represented by vectors within a Cartesian coordinate system and orientations in form of Euler angles (Vector3) or a rotation matrix (CFrame).
CFrame contains both positional and rotational data, while two Vector3 objects can be used to represent both data. However, CFrame rotations have more flexibility as CFrame uses a rotation matrix, which nullifies gimbal lock that is encountered when rotational data is represented by Euler angles (usually in form of three values).
There are some CFrame constructors that converts Euler angles to a rotational matrix: fromEulerAnglesYXZ (also Angles and fromOrientation), and fromEulerAnglesXYZ. The former is preferable for consistency with the camera.
World and Object[]
The terms World and Object are used to distinguish positional data that is a vector of the place's origin ("World", [0, 0, 0]) from other positional data that is a vector of another position ("Object", also known as an offset).
A Vector3 of another Vector3 can be converted into object space by subtracting the Vector3 by the other Vector3 to obtain the offset. Similarly, a CFrame of another CFrame can be converted using this method: offset = A:inverse() * B
. The method CFrame:ToObjectSpace can be used instead, replacing the inverse method with this: offset = A:ToObjectSpace(B)
.
Studs[]
Roblox uses a unit called "studs" as a measure of distance. A stud is the equivalent of one of the squares on a part's surface. A meter used to be equal to 20 studs[1], but now, 1 stud is equal to 0.28 meters.[2]
2D[]
There are three data types that represent a 2D position: UDim, UDim2 and Vector2. Some properties of instances that are related to the screen or the viewport, such as Camera, uses Vector2 (e.g. ViewportSize). Many properties of GUI elements use UDim and UDim2, but some properties also use Vector2 (e.g. AnchorPoint).
UDim and UDim2 properties are different from other data types in that both data types have a relative Scale property that is based on the properties of an instance's parent, or the screen by default, making UDim and UDim2 more suitable for developing GUIs to be compatible with different screen sizes.
References[]
- ↑ Sorcus (2012, June 7). "Testing the Accuracy of ROBLOX Physics with Potato Cannons". From Roblox Blog. Accessed May 22, 2023. Archived from the original on June 10, 2012.
- ↑ XAXA (2019, April 9). "How many studs is there in a meter". From DevForum. Accessed May 22, 2023. Archived from the original on March 27, 2021.
External links[]
- CFrames on the Roblox Creator Documentation
- CFrame data type on the Roblox Creator Documentation