Inverse Transform Direction in C++

Hi there,

I was digging how to get direction/angle from code to simplify my BP and this is what I found: the same functions are available as part of the UKismetMathLibrary as below

&

3_cpp2

Taking a look at the implementation, we could even cut some corners (and avoid extra #includes) with something like

and then the BP can go from

To

4_get_direction

Hope it helps. Regards

1 Like

I didn’t look to see if these functions are completely fine but KismetMathLibrary comes with a warning which I feel is good to post regardless:

“Just one thing to be aware of, make sure that whatever functions you’re trying to use are not part of the MINIMAL_API Macro (which you can find next to the class definition in the Header file). That Macro prevents those functions from being exported, so you can’t link against them when you compile and you’ll get compiler errors.”

void UMyPlayer_AnimInstance::NativeUpdateAnimation(float DeltaSecond)
{
	Super::NativeUpdateAnimation(DeltaSecond);

	if (plyrMovtPwn && plyrPwn) {
		if ((plyrChar = Cast<ANewPlayer_Character>(plyrPwn)) != nullptr) {
			SpdVlu = plyrPwn->GetVelocity().Size();
			//AnglVlu = plyrPwn->GetActorTransform().InverseTransformRotation()
			AnglVlu = FRotationMatrix::MakeFromX(plyrPwn->GetActorTransform().InverseTransformPositionNoScale(plyrPwn->GetVelocity())).Rotator().Yaw;

			//plyrIsJump = plyrMovtPwn->IsFalling();
		}
	}
}

Privacy & Terms