Vector3 Abs()

book_4_sparkGenerated
code_blocksInput

Description

The Abs method of the Vector3 struct returns a new vector where each component is the absolute value of the corresponding component in the original vector. This means that any negative values in the vector are converted to positive values, effectively mirroring the vector across the origin in 3D space.

Usage

Use the Abs method when you need to ensure that all components of a vector are non-negative. This can be useful in scenarios where directionality is not important, but magnitude is, such as when calculating distances or when you need to work with positive-only values.

Example

Vector3 vector = new Vector3(-3.0f, 4.0f, -5.0f);
Vector3 absoluteVector = vector.Abs();
// absoluteVector is now (3.0f, 4.0f, 5.0f)