Class VirtualTransform
Represents a detached transform that enables transform operations without being attached
to a GameObject. Unlike Unity's Transform component, VirtualTransform allows
calculations and manipulations without affecting the world state or requiring a scene
hierarchy.
Implements
Inherited Members
Namespace: Scylla.Core.Util
Assembly: ScyllaCore.dll
Syntax
public class VirtualTransform : IEquatable<VirtualTransform>
Remarks
Thread safety: This class is not thread-safe. All reads and writes must occur on the Unity main thread. Do not share instances across threads without external synchronisation.
Mutability: VirtualTransform is a mutable reference type. Its
Position, Rotation, and LocalScale properties
can be changed at any time, in contrast to Unity's Transform component which is
tightly coupled to the scene hierarchy and physics engine.
Common use cases:
- Preview calculations - evaluate a future transform state before committing it to a real GameObject, for example testing collision avoidance.
- Camera target interpolation - store a desired camera position and orientation and blend toward it each frame without needing a placeholder GameObject in the scene.
- Undo/redo snapshots - capture the full transform state of an object at a point in time as a plain C# object that can be stored and restored later.
-
Serialisation without a scene dependency - persist or transmit transform
data (position, rotation, scale) without requiring a live
GameObject.
Other Scylla types that follow a similar pattern of holding state that is updated manually each frame for interpolation targets include Timer and ColorAnimationText.
Constructors
VirtualTransform()
Creates a VirtualTransform at the world origin with identity rotation and unit scale.
Declaration
public VirtualTransform()
VirtualTransform(VirtualTransform)
Creates a VirtualTransform by copying properties from another VirtualTransform.
Declaration
public VirtualTransform(VirtualTransform other)
Parameters
| Type | Name | Description |
|---|---|---|
| VirtualTransform | other | The VirtualTransform to copy from. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if other is null. |
VirtualTransform(Camera)
Creates a VirtualTransform by copying properties from a Camera's transform.
Declaration
public VirtualTransform(Camera camera)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The Camera whose transform to copy from. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if camera is null. |
VirtualTransform(GameObject)
Creates a VirtualTransform by copying properties from a GameObject's transform.
Declaration
public VirtualTransform(GameObject gameObject)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | gameObject | The GameObject whose transform to copy from. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if gameObject is null. |
VirtualTransform(MonoBehaviour)
Creates a VirtualTransform by copying properties from a MonoBehaviour's transform.
Declaration
public VirtualTransform(MonoBehaviour monoBehaviour)
Parameters
| Type | Name | Description |
|---|---|---|
| MonoBehaviour | monoBehaviour | The MonoBehaviour whose transform to copy from. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if monoBehaviour is null. |
VirtualTransform(Quaternion)
Creates a VirtualTransform at the world origin with the specified rotation and unit scale.
Declaration
public VirtualTransform(Quaternion rotation)
Parameters
| Type | Name | Description |
|---|---|---|
| Quaternion | rotation | The world space rotation. |
VirtualTransform(Transform)
Creates a VirtualTransform by copying properties from a Unity Transform.
Declaration
public VirtualTransform(Transform transform)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | transform | The Transform to copy from. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if transform is null. |
VirtualTransform(Vector3)
Creates a VirtualTransform at the specified position with identity rotation and unit scale.
Declaration
public VirtualTransform(Vector3 position)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | position | The world space position. |
VirtualTransform(Vector3, Quaternion)
Creates a VirtualTransform with the specified position and rotation, and unit scale.
Declaration
public VirtualTransform(Vector3 position, Quaternion rotation)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | position | The world space position. |
| Quaternion | rotation | The world space rotation. |
VirtualTransform(Vector3, Quaternion, Vector3)
Creates a VirtualTransform with the specified position, rotation, and scale.
Declaration
public VirtualTransform(Vector3 position, Quaternion rotation, Vector3 localScale)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | position | The world space position. |
| Quaternion | rotation | The world space rotation. |
| Vector3 | localScale | The local scale. |
Properties
EulerAngles
Gets or sets the rotation of the transform expressed as Euler angles in degrees.
Declaration
public Vector3 EulerAngles { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector3 | The rotation as a |
Remarks
Euler angles are susceptible to gimbal lock - when two rotation axes align, a degree
of freedom is lost and the representation becomes ambiguous. For robust interpolation
and composition of rotations, prefer working directly with Rotation
(a quaternion). Use EulerAngles only when a human-readable degree representation
is required, such as when serialising or displaying values in a UI.
Forward
Gets the forward direction (blue axis / Z+) of the transform in world space.
Declaration
public Vector3 Forward { get; }
Property Value
| Type | Description |
|---|---|
| Vector3 | A normalised |
Remarks
This direction is derived by rotating Vector3.forward by Rotation
and normalising the result. The returned vector always has unit length, regardless
of the value of LocalScale.
LocalScale
Gets or sets the scale of the transform relative to its parent (or the world if no parent context is used).
Declaration
public Vector3 LocalScale { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector3 | The local scale as a |
Position
Gets or sets the position of the transform in world space.
Declaration
public Vector3 Position { get; set; }
Property Value
| Type | Description |
|---|---|
| Vector3 | The world-space position as a |
Right
Gets the right direction (red axis / X+) of the transform in world space.
Declaration
public Vector3 Right { get; }
Property Value
| Type | Description |
|---|---|
| Vector3 | A normalised |
Remarks
This direction is derived by rotating Vector3.right by Rotation
and normalising the result. The returned vector always has unit length, regardless
of the value of LocalScale.
Rotation
Gets or sets the rotation of the transform in world space, stored as a quaternion.
Declaration
public Quaternion Rotation { get; set; }
Property Value
| Type | Description |
|---|---|
| Quaternion | The world-space rotation as a |
Up
Gets the upward direction (green axis / Y+) of the transform in world space.
Declaration
public Vector3 Up { get; }
Property Value
| Type | Description |
|---|---|
| Vector3 | A normalised |
Remarks
This direction is derived by rotating Vector3.up by Rotation
and normalising the result. The returned vector always has unit length, regardless
of the value of LocalScale.
Methods
Apply(VirtualTransform)
Copies properties from another VirtualTransform to this VirtualTransform.
Declaration
public void Apply(VirtualTransform other)
Parameters
| Type | Name | Description |
|---|---|---|
| VirtualTransform | other | The VirtualTransform to copy from. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if other is null. |
Apply(Camera)
Copies properties from a Camera's transform to this VirtualTransform.
Declaration
public void Apply(Camera camera)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The Camera whose transform to copy from. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if camera is null. |
Apply(GameObject)
Copies properties from a GameObject's transform to this VirtualTransform.
Declaration
public void Apply(GameObject gameObject)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | gameObject | The GameObject whose transform to copy from. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if gameObject is null. |
Apply(MonoBehaviour)
Copies properties from a MonoBehaviour's transform to this VirtualTransform.
Declaration
public void Apply(MonoBehaviour monoBehaviour)
Parameters
| Type | Name | Description |
|---|---|---|
| MonoBehaviour | monoBehaviour | The MonoBehaviour whose transform to copy from. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if monoBehaviour is null. |
Apply(Transform)
Copies the position, rotation, and scale from a Unity Transform into this
VirtualTransform, overwriting all three properties.
Declaration
public void Apply(Transform transform)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | transform | The |
Remarks
Position and Rotation are copied from the
Transform's world-space properties (position and rotation).
LocalScale is copied from Transform.localScale - this matches
Unity's own behaviour where scale is always stored and manipulated in local space.
After this call this instance is an exact snapshot of the supplied
Transform at the moment of the call.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if transform is null. |
ApplyTo(VirtualTransform, bool)
Applies this VirtualTransform's properties to another VirtualTransform.
Declaration
public void ApplyTo(VirtualTransform other, bool applyScale = false)
Parameters
| Type | Name | Description |
|---|---|---|
| VirtualTransform | other | The VirtualTransform to apply to. |
| bool | applyScale | Whether to also apply the scale. Defaults to false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if other is null. |
ApplyTo(Camera, bool)
Applies this VirtualTransform's properties to a Camera's transform.
Declaration
public void ApplyTo(Camera camera, bool applyScale = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The Camera whose transform to apply to. |
| bool | applyScale | Whether to also apply the scale. Defaults to false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if camera is null. |
ApplyTo(GameObject, bool)
Applies this VirtualTransform's properties to a GameObject's transform.
Declaration
public void ApplyTo(GameObject gameObject, bool applyScale = false)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | gameObject | The GameObject whose transform to apply to. |
| bool | applyScale | Whether to also apply the scale. Defaults to false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if gameObject is null. |
ApplyTo(MonoBehaviour, bool)
Applies this VirtualTransform's properties to a MonoBehaviour's transform.
Declaration
public void ApplyTo(MonoBehaviour monoBehaviour, bool applyScale = false)
Parameters
| Type | Name | Description |
|---|---|---|
| MonoBehaviour | monoBehaviour | The MonoBehaviour whose transform to apply to. |
| bool | applyScale | Whether to also apply the scale. Defaults to false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if monoBehaviour is null. |
ApplyTo(Transform, bool)
Writes this VirtualTransform's position and rotation to a Unity
Transform, and optionally its scale.
Declaration
public void ApplyTo(Transform transform, bool applyScale = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | transform | The |
| bool | applyScale | When |
Remarks
Scale application is opt-in (defaults to false) because scale changes are
frequently undesirable in practice. Applying a stored scale to a Transform
can produce unexpected visual artifacts - particularly when the Transform
has a parent with non-uniform scale, because Unity compounds scales down the
hierarchy. Separating scale from the default write operation avoids accidental
scale bleed when this method is used for common operations such as camera placement
or character teleportation.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
Equals(VirtualTransform)
Determines whether this VirtualTransform is equal to another VirtualTransform.
Declaration
public bool Equals(VirtualTransform other)
Parameters
| Type | Name | Description |
|---|---|---|
| VirtualTransform | other | The VirtualTransform to compare with. |
Returns
| Type | Description |
|---|---|
| bool | True if both VirtualTransforms have equal position, rotation, and scale. |
Equals(object)
Determines whether this VirtualTransform is equal to another object.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with. |
Returns
| Type | Description |
|---|---|
| bool | True if the object is a VirtualTransform with equal values. |
Overrides
GetHashCode()
Returns a hash code for this VirtualTransform.
Warning: VirtualTransform is mutable by design. If you use it as a dictionary key or in a HashSet, do not modify its properties after insertion, or the object may become unfindable in the collection.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code based on position, rotation, and scale. |
Overrides
GetLocalPosition(VirtualTransform)
Calculates the local position relative to a parent VirtualTransform.
Declaration
public Vector3 GetLocalPosition(VirtualTransform parent)
Parameters
| Type | Name | Description |
|---|---|---|
| VirtualTransform | parent | The parent VirtualTransform. |
Returns
| Type | Description |
|---|---|
| Vector3 | The local position relative to the parent. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if parent is null. |
GetLocalPosition(Transform)
Calculates the local position relative to a parent Transform.
Declaration
public Vector3 GetLocalPosition(Transform parentTransform)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | parentTransform | The parent Transform. |
Returns
| Type | Description |
|---|---|
| Vector3 | The local position relative to the parent. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if parentTransform is null. |
GetLocalPosition(Vector3)
Calculates the local position relative to a parent position.
Declaration
public Vector3 GetLocalPosition(Vector3 parentPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | parentPosition | The parent's world position. |
Returns
| Type | Description |
|---|---|
| Vector3 | The local position relative to the parent. |
GetLocalRotation(VirtualTransform)
Calculates the local rotation relative to a parent VirtualTransform.
Declaration
public Quaternion GetLocalRotation(VirtualTransform parent)
Parameters
| Type | Name | Description |
|---|---|---|
| VirtualTransform | parent | The parent VirtualTransform. |
Returns
| Type | Description |
|---|---|
| Quaternion | The local rotation relative to the parent. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if parent is null. |
GetLocalRotation(Quaternion)
Calculates the local rotation relative to a parent rotation.
Declaration
public Quaternion GetLocalRotation(Quaternion parentRotation)
Parameters
| Type | Name | Description |
|---|---|---|
| Quaternion | parentRotation | The parent's world rotation. |
Returns
| Type | Description |
|---|---|
| Quaternion | The local rotation relative to the parent. |
GetLocalRotation(Transform)
Calculates the local rotation relative to a parent Transform.
Declaration
public Quaternion GetLocalRotation(Transform parentTransform)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | parentTransform | The parent Transform. |
Returns
| Type | Description |
|---|---|
| Quaternion | The local rotation relative to the parent. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if parentTransform is null. |
InverseTransformDirection(Vector3)
Converts a direction vector from world space into this transform's local space, applying only the inverse rotation component of the transform.
Declaration
public Vector3 InverseTransformDirection(Vector3 worldDirection)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | worldDirection | The direction vector expressed in world space. |
Returns
| Type | Description |
|---|---|
| Vector3 | The equivalent direction vector in local space. |
Remarks
Direction vectors represent orientations rather than positions, so they are unaffected by Position and LocalScale. Only the inverse of Rotation is applied. This makes the method suitable for converting world-space velocity or force vectors into the local frame of this transform without accidentally translating or scaling them.
The input vector's length is preserved. To convert a world-space position, use InverseTransformPoint(Vector3) instead.
InverseTransformPoint(Vector3)
Converts a point from world space into this transform's local space.
Declaration
public Vector3 InverseTransformPoint(Vector3 worldPoint)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | worldPoint | The point expressed in world-space coordinates. |
Returns
| Type | Description |
|---|---|
| Vector3 | The equivalent local-space position. This is the inverse of
TransformPoint(Vector3): applying |
Remarks
Zero scale components are handled safely: if any axis of LocalScale
is exactly 0, the corresponding local-space axis of the result is returned
as 0 rather than causing a division-by-zero error. This mirrors Unity's
behaviour and prevents NaN propagation in edge-case transforms.
Lerp(VirtualTransform, VirtualTransform, float)
Linearly interpolates between two VirtualTransform instances and returns the
result as a new VirtualTransform.
Declaration
public static VirtualTransform Lerp(VirtualTransform from, VirtualTransform to, float t)
Parameters
| Type | Name | Description |
|---|---|---|
| VirtualTransform | from | The starting transform, returned when |
| VirtualTransform | to | The ending transform, returned when |
| float | t | The normalised interpolation factor. Values outside [0, 1] are clamped - use LerpUnclamped(VirtualTransform, VirtualTransform, float) if extrapolation is required. |
Returns
| Type | Description |
|---|---|
| VirtualTransform | A new |
Remarks
Although this method is named Lerp, the rotation component uses
Quaternion.Slerp (spherical linear interpolation) internally rather than a
naive linear blend. This ensures the rotation travels along the shortest arc between
from.Rotation and to.Rotation
without distortion or loss of unit length.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
See Also
LerpUnclamped(VirtualTransform, VirtualTransform, float)
Linearly interpolates between two VirtualTransform instances without clamping
the interpolation factor, and returns the result as a new VirtualTransform.
Declaration
public static VirtualTransform LerpUnclamped(VirtualTransform from, VirtualTransform to, float t)
Parameters
| Type | Name | Description |
|---|---|---|
| VirtualTransform | from | The starting transform, returned when |
| VirtualTransform | to | The ending transform, returned when |
| float | t | The interpolation factor. Unlike Lerp(VirtualTransform, VirtualTransform, float), this value is not clamped to [0, 1], allowing extrapolation beyond the two endpoints. |
Returns
| Type | Description |
|---|---|
| VirtualTransform | A new |
Remarks
When t is outside [0, 1], position and scale values are
extrapolated beyond the supplied endpoints. For example, t = 1.5f produces
a transform halfway past to in the same direction. Be aware that
position may overshoot significantly; scale may reach negative values; and rotation
may spin past the intended target orientation. Use this overload only when
intentional overshoot or elastic behaviour is desired.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
See Also
LookAt(VirtualTransform)
Rotates to face a VirtualTransform's position using Vector3.up as the world up direction.
Declaration
public void LookAt(VirtualTransform other)
Parameters
| Type | Name | Description |
|---|---|---|
| VirtualTransform | other | The VirtualTransform to look at. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if other is null. |
LookAt(VirtualTransform, Vector3)
Rotates to face a VirtualTransform's position with a custom world up direction.
Declaration
public void LookAt(VirtualTransform other, Vector3 worldUp)
Parameters
| Type | Name | Description |
|---|---|---|
| VirtualTransform | other | The VirtualTransform to look at. |
| Vector3 | worldUp | The upward direction. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if other is null. |
LookAt(Camera, Vector3)
Rotates to face a Camera's position with a custom world up direction.
Declaration
public void LookAt(Camera camera, Vector3 worldUp)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The Camera to look at. |
| Vector3 | worldUp | The upward direction. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if camera is null. |
LookAt(GameObject)
Rotates to face a GameObject's position using Vector3.up as the world up direction.
Declaration
public void LookAt(GameObject gameObject)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | gameObject | The GameObject to look at. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if gameObject is null. |
LookAt(GameObject, Vector3)
Rotates to face a GameObject's position with a custom world up direction.
Declaration
public void LookAt(GameObject gameObject, Vector3 worldUp)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | gameObject | The GameObject to look at. |
| Vector3 | worldUp | The upward direction. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if gameObject is null. |
LookAt(MonoBehaviour)
Rotates to face a MonoBehaviour's position using Vector3.up as the world up direction.
Declaration
public void LookAt(MonoBehaviour monoBehaviour)
Parameters
| Type | Name | Description |
|---|---|---|
| MonoBehaviour | monoBehaviour | The MonoBehaviour to look at. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if monoBehaviour is null. |
LookAt(MonoBehaviour, Vector3)
Rotates to face a MonoBehaviour's position with a custom world up direction.
Declaration
public void LookAt(MonoBehaviour monoBehaviour, Vector3 worldUp)
Parameters
| Type | Name | Description |
|---|---|---|
| MonoBehaviour | monoBehaviour | The MonoBehaviour to look at. |
| Vector3 | worldUp | The upward direction. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if monoBehaviour is null. |
LookAt(Transform)
Rotates to face a Transform's position using Vector3.up as the world up direction.
Declaration
public void LookAt(Transform transform)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | transform | The Transform to look at. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if transform is null. |
LookAt(Transform, Vector3)
Rotates to face a Transform's position with a custom world up direction.
Declaration
public void LookAt(Transform transform, Vector3 worldUp)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | transform | The Transform to look at. |
| Vector3 | worldUp | The upward direction. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if transform is null. |
LookAt(Vector3)
Rotates to face a target position using Vector3.up as the world up direction.
Declaration
public void LookAt(Vector3 target)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | target | The world space position to look at. |
LookAt(Vector3, Vector3)
Rotates this transform to face a target world-space position, using a custom world up direction to determine the orientation's roll.
Declaration
public void LookAt(Vector3 target, Vector3 worldUp)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | target | The world-space position to look toward. |
| Vector3 | worldUp | The upward direction used to resolve the roll component of the resulting rotation.
Typically |
Remarks
Internally this method computes the direction from Position to
target and passes it to Quaternion.LookRotation. To
prevent degenerate rotations - which arise when the target is too close to the
current position and the direction vector has near-zero length - the rotation is
only applied when the squared magnitude of the direction exceeds 0.0001. When the
check fails, Rotation is left unchanged.
Rotate(float, float, float)
Rotates the transform by Euler angles in degrees in world space.
Declaration
public void Rotate(float x, float y, float z)
Parameters
| Type | Name | Description |
|---|---|---|
| float | x | The X rotation in degrees. |
| float | y | The Y rotation in degrees. |
| float | z | The Z rotation in degrees. |
Rotate(float, float, float, Space)
Rotates the transform by Euler angles in degrees in the given coordinate space.
Declaration
public void Rotate(float x, float y, float z, Space space)
Parameters
| Type | Name | Description |
|---|---|---|
| float | x | The X rotation in degrees. |
| float | y | The Y rotation in degrees. |
| float | z | The Z rotation in degrees. |
| Space | space | The coordinate space (World or Self). |
Rotate(Quaternion, Space)
Rotates the transform by the specified quaternion in the given coordinate space.
Declaration
public void Rotate(Quaternion rotation, Space space = Space.World)
Parameters
| Type | Name | Description |
|---|---|---|
| Quaternion | rotation | The rotation to apply. |
| Space | space | The coordinate space (World or Self). Defaults to World. |
Rotate(Vector3)
Rotates the transform by Euler angles in degrees in world space.
Declaration
public void Rotate(Vector3 eulerAngles)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | eulerAngles | The Euler angles in degrees. |
Rotate(Vector3, float)
Rotates the transform around the specified axis by the specified angle in world space.
Declaration
public void Rotate(Vector3 axis, float angle)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | axis | The axis to rotate around. |
| float | angle | The angle in degrees. |
Rotate(Vector3, float, Space)
Rotates the transform around the specified axis by the specified angle in the given coordinate space.
Declaration
public void Rotate(Vector3 axis, float angle, Space space)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | axis | The axis to rotate around. |
| float | angle | The angle in degrees. |
| Space | space | The coordinate space (World or Self). |
Rotate(Vector3, Space)
Rotates the transform by Euler angles in degrees in the given coordinate space.
Declaration
public void Rotate(Vector3 eulerAngles, Space space)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | eulerAngles | The Euler angles in degrees. |
| Space | space | The coordinate space (World or Self). |
RotateAround(VirtualTransform, float)
Rotates around a VirtualTransform's position by the specified angle on the Y axis.
Declaration
public void RotateAround(VirtualTransform other, float angle)
Parameters
| Type | Name | Description |
|---|---|---|
| VirtualTransform | other | The VirtualTransform whose position to rotate around. |
| float | angle | The angle in degrees. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if other is null. |
RotateAround(VirtualTransform, float, Vector3)
Rotates around a VirtualTransform's position by the specified angle on the given axis.
Declaration
public void RotateAround(VirtualTransform other, float angle, Vector3 axis)
Parameters
| Type | Name | Description |
|---|---|---|
| VirtualTransform | other | The VirtualTransform whose position to rotate around. |
| float | angle | The angle in degrees. |
| Vector3 | axis | The axis to rotate around. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if other is null. |
RotateAround(Camera, float, Vector3)
Rotates around a Camera's position by the specified angle on the given axis.
Declaration
public void RotateAround(Camera camera, float angle, Vector3 axis)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | camera | The Camera whose position to rotate around. |
| float | angle | The angle in degrees. |
| Vector3 | axis | The axis to rotate around. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if camera is null. |
RotateAround(GameObject, float)
Rotates around a GameObject's position by the specified angle on the Y axis.
Declaration
public void RotateAround(GameObject gameObject, float angle)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | gameObject | The GameObject whose position to rotate around. |
| float | angle | The angle in degrees. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if gameObject is null. |
RotateAround(GameObject, float, Vector3)
Rotates around a GameObject's position by the specified angle on the given axis.
Declaration
public void RotateAround(GameObject gameObject, float angle, Vector3 axis)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | gameObject | The GameObject whose position to rotate around. |
| float | angle | The angle in degrees. |
| Vector3 | axis | The axis to rotate around. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if gameObject is null. |
RotateAround(MonoBehaviour, float)
Rotates around a MonoBehaviour's position by the specified angle on the Y axis.
Declaration
public void RotateAround(MonoBehaviour monoBehaviour, float angle)
Parameters
| Type | Name | Description |
|---|---|---|
| MonoBehaviour | monoBehaviour | The MonoBehaviour whose position to rotate around. |
| float | angle | The angle in degrees. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if monoBehaviour is null. |
RotateAround(MonoBehaviour, float, Vector3)
Rotates around a MonoBehaviour's position by the specified angle on the given axis.
Declaration
public void RotateAround(MonoBehaviour monoBehaviour, float angle, Vector3 axis)
Parameters
| Type | Name | Description |
|---|---|---|
| MonoBehaviour | monoBehaviour | The MonoBehaviour whose position to rotate around. |
| float | angle | The angle in degrees. |
| Vector3 | axis | The axis to rotate around. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if monoBehaviour is null. |
RotateAround(Transform, float)
Rotates around a Transform's position by the specified angle on the Y axis.
Declaration
public void RotateAround(Transform transform, float angle)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | transform | The Transform whose position to rotate around. |
| float | angle | The angle in degrees. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if transform is null. |
RotateAround(Transform, float, Vector3)
Rotates around a Transform's position by the specified angle on the given axis.
Declaration
public void RotateAround(Transform transform, float angle, Vector3 axis)
Parameters
| Type | Name | Description |
|---|---|---|
| Transform | transform | The Transform whose position to rotate around. |
| float | angle | The angle in degrees. |
| Vector3 | axis | The axis to rotate around. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if transform is null. |
RotateAround(Vector3, float)
Rotates around a pivot point by the specified angle on the Y axis (Vector3.up).
Declaration
public void RotateAround(Vector3 pivot, float angle)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | pivot | The world space position to rotate around. |
| float | angle | The angle in degrees. |
RotateAround(Vector3, float, Vector3)
Rotates this transform around a world-space pivot point by the given angle on the specified axis, updating both position and orientation.
Declaration
public void RotateAround(Vector3 pivot, float angle, Vector3 axis)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | pivot | The world-space point to orbit around. |
| float | angle | The clockwise rotation angle in degrees (using the right-hand rule). |
| Vector3 | axis | The world-space axis to rotate around. Should be a normalised vector for predictable
results; for example |
Remarks
The algorithm proceeds in two steps. First, the direction vector from
pivot to Position is computed and rotated by the
requested quaternion; Position is then set to
pivot + rotatedDirection. Second, the same quaternion is composed onto
Rotation so that the transform's orientation tracks the orbit - the
transform always faces the same relative direction after the rotation.
Slerp(VirtualTransform, VirtualTransform, float)
Spherically interpolates between two VirtualTransform instances and returns
the result as a new VirtualTransform.
Declaration
public static VirtualTransform Slerp(VirtualTransform from, VirtualTransform to, float t)
Parameters
| Type | Name | Description |
|---|---|---|
| VirtualTransform | from | The starting transform, returned when |
| VirtualTransform | to | The ending transform, returned when |
| float | t | The normalised interpolation factor, clamped to [0, 1]. |
Returns
| Type | Description |
|---|---|
| VirtualTransform | A new |
Remarks
The key difference from Lerp(VirtualTransform, VirtualTransform, float) is that this method applies
Vector3.Slerp to the Position component in addition to using
Quaternion.Slerp for rotation. Position slerp treats the two positions as
directions from the origin and interpolates along the arc of a sphere, which
produces a curved path through 3D space rather than a straight line. This behaviour
is useful for camera orbits or any motion that should follow an arc, but it can be
surprising when the positions are near the origin or point in nearly opposite
directions. If a straight-line positional blend is required, use Lerp(VirtualTransform, VirtualTransform, float)
instead.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
See Also
ToString()
Returns a string representation of this VirtualTransform.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string showing position, rotation (as Euler angles), and scale. |
Overrides
TransformDirection(Vector3)
Converts a direction vector from this transform's local space into world space, applying only the rotation component of the transform.
Declaration
public Vector3 TransformDirection(Vector3 localDirection)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | localDirection | The direction vector expressed in local space. |
Returns
| Type | Description |
|---|---|
| Vector3 | The equivalent direction vector in world space. |
Remarks
Direction vectors represent orientations rather than positions, so they are unaffected by Position and LocalScale. Only Rotation is applied. This makes the method suitable for rotating velocity vectors, force vectors, or surface normals into world space without accidentally translating or scaling them.
The input vector's length is preserved. To transform a position, use TransformPoint(Vector3) instead.
TransformPoint(Vector3)
Converts a point from this transform's local space into world space.
Declaration
public Vector3 TransformPoint(Vector3 localPoint)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | localPoint | The point expressed in local space coordinates. |
Returns
| Type | Description |
|---|---|
| Vector3 | The equivalent world-space position obtained by applying this transform's full
TRS (translate-rotate-scale) matrix to |
Remarks
The transformation is applied in the order: scale first, then rotate, then
translate. This matches Unity's standard TRS pipeline:
worldPoint = Position + Rotation * (LocalScale * localPoint).
To perform the reverse operation, use InverseTransformPoint(Vector3).
Translate(float, float, float)
Translates the position by the specified x, y, z values in world space.
Declaration
public void Translate(float x, float y, float z)
Parameters
| Type | Name | Description |
|---|---|---|
| float | x | The amount to move on the X axis. |
| float | y | The amount to move on the Y axis. |
| float | z | The amount to move on the Z axis. |
Translate(Vector3)
Translates the position by the specified movement vector in world space.
Declaration
public void Translate(Vector3 movement)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | movement | The movement vector to add to the position. |
Operators
operator ==(VirtualTransform, VirtualTransform)
Equality operator for two VirtualTransforms.
Declaration
public static bool operator ==(VirtualTransform left, VirtualTransform right)
Parameters
| Type | Name | Description |
|---|---|---|
| VirtualTransform | left | |
| VirtualTransform | right |
Returns
| Type | Description |
|---|---|
| bool |
operator !=(VirtualTransform, VirtualTransform)
Inequality operator for two VirtualTransforms.
Declaration
public static bool operator !=(VirtualTransform left, VirtualTransform right)
Parameters
| Type | Name | Description |
|---|---|---|
| VirtualTransform | left | |
| VirtualTransform | right |
Returns
| Type | Description |
|---|---|
| bool |