UKismetMathLibrary::CrossProduct2D
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Returns the 2D cross product (A.X*B.Y - A.Y*B.X), a scalar representing the signed area of the parallelogram spanned by A and B. Positive means B is counter-clockwise from A; negative means clockwise.
Caveats & Gotchas
- • The 2D cross product returns a scalar, not a vector. It is the Z component you would get from the 3D cross product of the two vectors embedded in XY space.
- • The sign convention depends on your coordinate system. UE uses a left-handed coordinate system, so positive values indicate a counter-clockwise turn from A to B when viewed down the Z axis.
Signature
static UE_INL_API double CrossProduct2D(FVector2D A, FVector2D B); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| A | FVector2D | The first 2D vector. | — |
| B | FVector2D | The second 2D vector. | — |
Return Type
double Example
Determine turn direction between two 2D directions C++
FVector2D Forward(1.f, 0.f);
FVector2D ToTarget(0.f, 1.f);
double Cross = UKismetMathLibrary::CrossProduct2D(Forward, ToTarget);
// Cross > 0: target is to the left; Cross < 0: target is to the right Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?