Description
The CameraTransform
property provides the transform of the camera in world space. This static property is part of the Gizmo
class within the Sandbox
namespace. It allows you to access the camera's position, rotation, and scale as a Transform
object, which is essential for manipulating or querying the camera's state in a 3D environment.
Usage
Use the CameraTransform
property when you need to obtain or utilize the camera's transform in world space. This can be particularly useful for operations that require knowledge of the camera's position and orientation, such as rendering, physics calculations, or user interface alignment.
Example
// Example of accessing the CameraTransform property
Transform cameraTransform = Gizmo.CameraTransform;
// Use the camera's position
Vector3 cameraPosition = cameraTransform.Position;
// Use the camera's rotation
Rotation cameraRotation = cameraTransform.Rotation;
// Use the camera's scale
Vector3 cameraScale = cameraTransform.Scale;
// Example of using the camera's transform in a function
void AlignObjectToCamera(GameObject obj)
{
obj.Transform.Position = cameraTransform.Position + cameraTransform.Rotation.Forward * 10.0f;
obj.Transform.Rotation = cameraTransform.Rotation;
}