【问题标题】:UE4 How to set pitch in controlRotation for AIControllerUE4 如何在控制旋转中为 AIController 设置音高
【发布时间】:2020-08-06 15:09:00
【问题描述】:

我尝试 setControlRotation 但 Pitch 总是忽略它。它仅适用于偏航

我还尝试在动画蓝图中设置 Pitch。似乎有些东西在动画蓝图之前改变了它,因为 Pitch 试图返回到以前的值

【问题讨论】:

  • 您能否详细说明您要做什么? AI是射手的敌人吗?是汽车/飞机吗?您还需要在此处编写代码,以便我们找出您到底错在哪里
  • 现在我发现我真正需要的是SetFocus,但我不能让它顺利转动。我为敌人制作了简单的射击游戏,一切都是为了 ai
  • 这能回答你的问题吗? answers.unrealengine.com/questions/897656/…

标签: unreal-engine4


【解决方案1】:

最后我通过创建特殊的简单棋子来瞄准:

  1. 创建棋子
  2. setFocus 在那颗棋子上
  3. 将棋子移到敌人的头上

【讨论】:

    【解决方案2】:

    默认 AIController 会覆盖此函数中的音高。您需要创建一个新的父级才能获得 AIController 的其他功能。

    void AEEAIController::UpdateControlRotation(float DeltaTime, bool bUpdatePawn)
    {
        APawn* const MyPawn = GetPawn();
        if (MyPawn)
        {
            FRotator NewControlRotation = GetControlRotation();
    
            // Look toward focus
            const FVector FocalPoint = GetFocalPoint();
            if (FAISystem::IsValidLocation(FocalPoint))
            {
                NewControlRotation = (FocalPoint - MyPawn->GetPawnViewLocation()).Rotation();
            }
            else if (bSetControlRotationFromPawnOrientation)
            {
                NewControlRotation = MyPawn->GetActorRotation();
            }
    
            // We override this so flying units can go up and down
            //// Don't pitch view unless looking at another pawn
            //if (NewControlRotation.Pitch != 0 && Cast<APawn>(GetFocusActor()) == nullptr)
            //{
            //  NewControlRotation.Pitch = 0.f;
            //}
    
            SetControlRotation(NewControlRotation);
    
            if (bUpdatePawn)
            {
                const FRotator CurrentPawnRotation = MyPawn->GetActorRotation();
    
                if (CurrentPawnRotation.Equals(NewControlRotation, 1e-3f) == false)
                {
                    MyPawn->FaceRotation(NewControlRotation, DeltaTime);
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多