UE4 FVector::SizeSquared2D()

这段代码定义了一个FVector类的方法SizeSquared2D,用于计算二维向量的平方长度。该方法通过直接相乘并求和向量的X和Y分量来实现,返回值为平方长度。

/**
* 得到这个向量的二维分量的平方长度。
*
*/

//Vector.h
	/**
	 * Get the squared length of the 2D components of this vector.
	 *
	 * @return The squared 2D length of this vector.
	 */
	float SizeSquared2D() const ;

FORCEINLINE float FVector::SizeSquared2D() const 
{
	return X*X + Y*Y;
}
void ATFPlayerCharacter::FixFaceDirection() { if (MovementComponent->GetLastInputVector().Length() == 0 && MainAnimInstance && MainAnimInstance->GetRootMotionMontageInstance() == nullptr && GetLockedTarget()) { const FVector PivotLoc = MovementComponent->UpdatedComponent->GetComponentLocation(); const FRotator PivotRot = MovementComponent->UpdatedComponent->GetComponentRotation(); const FVector TargetLocation = GetLockOnCapturedPointLoc(); const FRotator TargetRotation = GetLockOnCapturePointRot(); const FVector PivotForward = MovementComponent->GetForwardVector().GetSafeNormal2D(); const FVector TargetDirection = (TargetLocation - PivotLoc).GetSafeNormal2D(); float AngleDot = FVector::DotProduct(PivotForward, TargetDirection); float Angle = FMath::RadiansToDegrees(FMath::Acos(AngleDot)); const FVector ToTarget = TargetLocation - PivotLoc; const double DesiredYaw = FMath::RadiansToDegrees(FMath::Atan2(ToTarget.Y, ToTarget.X)); if (FMath::Abs(Angle) > 50.f) { if (bIsDefensing) { FRotator FaceDirection = (GetLockedTarget()->GetActorLocation() - GetActorLocation()).Rotation(); FaceDirection.Pitch = 0.0f; FaceDirection.Roll = 0.0f; SetActorRotation(FaceDirection); } else if (bEnableTurnInPlace) { FName WarpSlot; UAnimMontage* RightMontage_90 = nullptr; UAnimMontage* RightMontage_180 = nullptr; UAnimMontage* LeftMontage_90 = nullptr; UAnimMontage* LeftMontage_180 = nullptr; if (nullptr != MainAnimInstance.Get()) { if (UTFAnimInstanceLayers* AnimLayer = Cast<UTFAnimInstanceLayers>(MainAnimInstance->LastLinkedLayer.Get())) { WarpSlot = AnimLayer->TFMotionSet->StandingAnimations.IdleAndTurnInPlace.TurnInPlaceAnims.TIPSocketName; RightMontage_90 = AnimLayer->TFMotionSet->StandingAnimations.IdleAndTurnInPlace.TurnInPlaceAnims.AnimMontage_Right_90; LeftMontage_90 = AnimLayer->TFMotionSet->StandingAnimations.IdleAndTurnInPlace.TurnInPlaceAnims.AnimMontage_Left_90; RightMontage_180 = AnimLayer->TFMotionSet->StandingAnimations.IdleAndTurnInPlace.TurnInPlaceAnims.AnimMontage_Right_180; RightMontage_180 = RightMontage_180 == nullptr ? RightMontage_90 : RightMontage_180; LeftMontage_180 = AnimLayer->TFMotionSet->StandingAnimations.IdleAndTurnInPlace.TurnInPlaceAnims.AnimMontage_Left_180; LeftMontage_180 = LeftMontage_180 == nullptr ? LeftMontage_90 : LeftMontage_180; } } bool IsRight = FVector::CrossProduct(PivotForward, TargetDirection).Z > 0; UAnimMontage* TIPMontage = IsRight ? Angle > 90.f ? RightMontage_180 : RightMontage_90 : Angle > 90.f ? LeftMontage_180 : LeftMontage_90; PlayTurnMontage(TargetLocation, TargetRotation, TIPMontage, WarpSlot, Angle); UE_LOG(LogAnimation, Warning, TEXT("AngleDot : %f, Angle : %f, IsRight : %d, Distance : %f"), AngleDot, Angle, IsRight, FVector::Distance(this->GetActorLocation(), GetLockedTarget()->GetActorLocation())); } } } } 这段UE代码的功能是什么,也讲解一下实现的逻辑,为什么战斗中一直没进这个判断?
最新发布
11-11
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值