Vector2 Abs()

book_4_sparkGenerated
code_blocksInput

Description

The Abs method of the Vector2 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, while positive values remain unchanged.

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, and you are only interested in the magnitude of the vector components.

Example

Vector2 vector = new Vector2(-3.5f, 4.2f);
Vector2 absoluteVector = vector.Abs();
// absoluteVector is now (3.5, 4.2)