Transform
The Transform class represents an object's position, rotation, and scale within a 3D space. It facilitates common operations such as moving an object to a new position or by a specified offset, rotating it to face a target point and much more making it essential for handling object transformations in 3D environments and game development scenarios.
Usage
To use this class, add the following require at the top of your script:
Reference
new
Creates a transform object from existing position, rotation, and scale.
Parameters
position(Vector3): The position.rotation(Quaternion): The rotation.scale(Vector3): The scale.
Returns
Transform: new Transform object.
fromJson
Creates a transform object from JSON.
Parameters
json(string): The JSON string.
Returns
Transform: new Transform object.
fromData
Creates a transform object from data.
Parameters
data(table): The data object containing position, rotation, and scale.
Returns
Transform: new Transform object.
toData
Converts the transform into a table representation.
Returns
table: data table.
clone
Clones the transform
Returns
table: cloned transform
moveTo
Moves the transform to a new position.
Parameters
x(number|Vector3): The x coordinate or a Vector3 position.y(number): The y coordinate (if x is a number).z(number): The z coordinate (if x is a number).
moveBy
Moves the transform by a given offset.
Parameters
x(number|Vector3): The x offset or a Vector3 offset.y(number): The y offset (if x is a number).z(number): The z offset (if x is a number).
lookAt
Rotates the transform to look at a target position.
Parameters
x(number|Vector3): The target x coordinate or a Vector3 target.y(number|Vector3): The target y coordinate (if x is a number) or the up vector in case x is the look at Vector.z(number): The target z coordinate (if x is a number).up(Vector3): The up direction (default is Vector3(0,1,0)).
rotateTo
Rotates the transform to a specific orientation. Angles are specified in degrees.
Parameters
x(number|Vector3): Rotation around the x-axis, or a Vector3 representing rotation.y(number): Rotation around the y-axis (if x is a number).z(number): Rotation around the z-axis (if x is a number).
rotateBy
Rotates the transform by the given amount. Angles are specified in degrees.
Parameters
x(number|Vector3): Rotation to apply around the x-axis, or a Vector3 representing rotation.y(number): Rotation to apply around the y-axis (if x is a number).z(number): Rotation to apply around the z-axis (if x is a number).
Class: Transform
new
Creates a transform object from existing position, rotation, and scale.
Parameters
position(Vector3): The position.rotation(Quaternion): The rotation.scale(Vector3): The scale.
Returns
Transform: new Transform object.
fromJson
Creates a transform object from JSON.
Parameters
json(string): The JSON string.
Returns
Transform: new Transform object.
fromData
Creates a transform object from data.
Parameters
data(table): The data object containing position, rotation, and scale.
Returns
Transform: new Transform object.
toData
Converts the transform into a table representation.
Returns
table: data table.
clone
Clones the transform
Returns
table: cloned transform
moveTo
Moves the transform to a new position.
Parameters
x(number|Vector3): The x coordinate or a Vector3 position.y(number): The y coordinate (if x is a number).z(number): The z coordinate (if x is a number).
moveBy
Moves the transform by a given offset.
Parameters
x(number|Vector3): The x offset or a Vector3 offset.y(number): The y offset (if x is a number).z(number): The z offset (if x is a number).
lookAt
Rotates the transform to look at a target position.
Parameters
x(number|Vector3): The target x coordinate or a Vector3 target.y(number|Vector3): The target y coordinate (if x is a number) or the up vector in case x is the look at Vector.z(number): The target z coordinate (if x is a number).up(Vector3): The up direction (default is Vector3(0,1,0)).
rotateTo
Rotates the transform to a specific orientation. Angles are specified in degrees.
Parameters
x(number|Vector3): Rotation around the x-axis, or a Vector3 representing rotation.y(number): Rotation around the y-axis (if x is a number).z(number): Rotation around the z-axis (if x is a number).
rotateBy
Rotates the transform by the given amount. Angles are specified in degrees.
Parameters
x(number|Vector3): Rotation to apply around the x-axis, or a Vector3 representing rotation.y(number): Rotation to apply around the y-axis (if x is a number).z(number): Rotation to apply around the z-axis (if x is a number).