I’ve been playing around with the engine for a while now, and I’ve been trying to find out how to find the relative position of a point (preferably, with a good accuracy, so angles would be the best way I guess), but I haven’t been very successful so far.
Cross product and then Dot product is a really quick and cheap way to know if something is to the left or right of something else.
From the old scripture… Legacy:UnrealScript Vector Maths - Unreal Wiki
You get the object-to-world transform of your char with ACharacter::GetTransform().
Inverse-transform your point with it. If the resulting transformed position has a negative Y-Component, the point is left of your character.
If it is positive, it is right of your character.
Code:
void ACharacter::Foo()
{
FTransform trafoCharToWorld = GetTransform();
FVector vecTest(...);
if ( trafoCharToWorld.InverseTranformPosition(vecTest).Y < 0 )
{
// left side of character
}
else if ( trafoCharToWorld.InverseTranformPosition(vecTest).Y > 0 )
{
// right side of character
}
@djchase- I’m so sorry, maybe I wasn’t clear, but I actually need the angle, well I could use the angle, because there will be points which aren’t at 180º/- 180º of the character, and those are the ones I need, I have to ignore all others… Sorry for not being clear the first time!
You can use the previous method additionaly if you want to know if it is a positive or negative angle.
(Although there should be a faster way without having to use linear algebra)
Perhaps googling for azimuth calculations would also help…