FVector UAbilityTask_ApplyRootMotionMoveToActorForce::CalculateTargetOffset() const
{
	check(TargetActor != nullptr);

	const FVector TargetActorLocation = TargetActor->GetActorLocation();
	FVector CalculatedTargetLocation = TargetActorLocation;
	
	if (OffsetAlignment == ERootMotionMoveToActorTargetOffsetType::AlignFromTargetToSource)
	{
		if (MovementComponent)
		{
			FVector ToSource = MovementComponent->GetActorLocation() - TargetActorLocation;
			ToSource.Z = 0.f;
			CalculatedTargetLocation += ToSource.ToOrientationQuat().RotateVector(TargetLocationOffset);
		}

	}
	else if (OffsetAlignment == ERootMotionMoveToActorTargetOffsetType::AlignToTargetForward)
	{
		CalculatedTargetLocation += TargetActor->GetActorQuat().RotateVector(TargetLocationOffset);
	}
	else if (OffsetAlignment == ERootMotionMoveToActorTargetOffsetType::AlignToWorldSpace)
	{
		CalculatedTargetLocation += TargetLocationOffset;
	}
	
	return CalculatedTargetLocation;
}
void ATP_FlyingPawn::NotifyHit(class UPrimitiveComponent* MyComp, class AActor* Other, class UPrimitiveComponent* OtherComp, bool bSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalImpulse, const FHitResult& Hit)
{
	Super::NotifyHit(MyComp, Other, OtherComp, bSelfMoved, HitLocation, HitNormal, NormalImpulse, Hit);

	// Deflect along the surface when we collide.
	FRotator CurrentRotation = GetActorRotation(RootComponent);
	SetActorRotation(FQuat::Slerp(CurrentRotation.Quaternion(), HitNormal.ToOrientationQuat(), 0.025f));
}
void AFloatingText::Update( const FVector OrientateToward )
{
	// Orientate it toward the viewer
	const FVector DirectionToward = ( OrientateToward - GetActorLocation() ).GetSafeNormal();

	const FQuat TowardRotation = DirectionToward.ToOrientationQuat();

	// @todo vreditor tweak
	const float LineRadius = 0.1f;
	const float FirstLineLength = 4.0f;	   // Default line length (note that socket scale can affect this!)
	const float SecondLineLength = TextComponent->GetTextLocalSize().Y;	// The second line "underlines" the text


	// NOTE: The origin of the actor will be the designated target of the text
	const FVector FirstLineLocation = FVector::ZeroVector;
	const FQuat FirstLineRotation = FVector::ForwardVector.ToOrientationQuat();
	const FVector FirstLineScale = FVector( FirstLineLength, LineRadius, LineRadius );
	FirstLineComponent->SetRelativeLocation( FirstLineLocation );
	FirstLineComponent->SetRelativeRotation( FirstLineRotation );
	FirstLineComponent->SetRelativeScale3D( FirstLineScale );

	// NOTE: The joint sphere draws at the connection point between the lines
	const FVector JointLocation = FirstLineLocation + FirstLineRotation * FVector::ForwardVector * FirstLineLength;
	const FVector JointScale = FVector( LineRadius );
	JointSphereComponent->SetRelativeLocation( JointLocation );
	JointSphereComponent->SetRelativeScale3D( JointScale );

	// NOTE: The second line starts at the joint location
	SecondLineComponent->SetWorldLocation( JointSphereComponent->GetComponentLocation() );
	SecondLineComponent->SetWorldRotation( ( TowardRotation * -FVector::RightVector ).ToOrientationQuat() );
	SecondLineComponent->SetRelativeScale3D( FVector( ( SecondLineLength / GetActorScale().X ) * GetWorld()->GetWorldSettings()->WorldToMeters / 100.0f, LineRadius, LineRadius ) );

	TextComponent->SetWorldLocation( JointSphereComponent->GetComponentLocation() );
	TextComponent->SetWorldRotation( ( TowardRotation * FVector::ForwardVector ).ToOrientationQuat() );

}