当前位置:   article > 正文

UE4 FindCollisionUV_ue4寻找碰撞uv

ue4寻找碰撞uv

FindCollisionUV可以做碰撞或击中某物件上碰撞点对应的UV坐标,我们可以基于该UV坐标作为材质参数传入到该物件材质中做一些碰撞或击中材质效果。注意:碰撞或射线检测,必须开启复杂检测,该物件设置开启物理。

  1. /**
  2. * Try and find the UV for a collision impact. Note this ONLY works if 'Support UV From Hit Results' is enabled in Physics Settings.
  3. */
  4. UFUNCTION(BlueprintPure, Category = "Collision")
  5. static bool FindCollisionUV(const struct FHitResult& Hit, int32 UVChannel, FVector2D& UV);
  6. bool UGameplayStatics::FindCollisionUV(const struct FHitResult& Hit, int32 UVChannel, FVector2D& UV)
  7. {
  8. bool bSuccess = false;
  9. if (!UPhysicsSettings::Get()->bSupportUVFromHitResults)
  10. {
  11. FMessageLog("PIE").Warning(LOCTEXT("CollisionUVNoSupport", "Calling FindCollisionUV but 'Support UV From Hit Results' is not enabled in project settings. This is required for finding UV for collision results."));
  12. }
  13. else
  14. {
  15. UPrimitiveComponent* HitPrimComp = Hit.Component.Get();
  16. if (HitPrimComp)
  17. {
  18. UBodySetup* BodySetup = HitPrimComp->GetBodySetup();
  19. if (BodySetup)
  20. {
  21. const FVector LocalHitPos = HitPrimComp->GetComponentToWorld().InverseTransformPosition(Hit.Location);
  22. bSuccess = BodySetup->CalcUVAtLocation(LocalHitPos, Hit.FaceIndex, UVChannel, UV);
  23. }
  24. }
  25. }
  26. return bSuccess;
  27. }

基于官方第一人称例子工程,使用如下图:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/91470
推荐阅读
相关标签
  

闽ICP备14008679号