• Chicken的代码解剖 :4 ChickenPawn_Chicken一小部分


      看看鸡是怎么被狐狸抓住的。在鸡的类中

    var Controller CarriedBy;

      这是狐狸的Controller,在上一节中我们学到,将鸡的Controller换为狐狸的就实现了他们两个之间的位置同步。然而还有一个插槽,让鸡飞到狐狸的嘴边,这样看起来像被叼着不是吗。

    function NotifyGrabbed(Controller Grabber)
    {
     super.NotifyGrabbed(Grabber);
    }

      原来我们在ChickenPawn类中漏掉了一个重要的函数,赶快把他拉过来看看。

    function NotifyGrabbed(controller Grabber)
    {
     ChickenAIController(controller).NotifyGrabbed(Grabber);
    }

      好吧,我们又被踢到类ChickenAIController中了,现在进入该类。

    function NotifyGrabbed(Controller Grabber)
    {
     GotoState('Grabber');
    }

      但愿你不会很烦,进入Grabber状态一探究竟。究竟是为什么要在Controller的状态中定义这么一套狐狸抓小鸡的动作呢?我们知道,狐狸和鸡都继承自这个Controller。

    State Grabber
    {
    //设置其物理为飞
       simulated event BeginState(name PreviousStateName)
       {
        Pawn.SetPhysics(PHYS_Flying);
        ClearTimer('CheckStuckTimer');
       }
    
    //在结束的时候将其速度设为0   
       simulated event EndState(name NextStateName)
       {
        StopLatentExecution();
        Pawn.velocity*=0;
       }
    
    //一会看看怎么定义外部Tick函数的   
       simulated event Tick(float DeltaTime)
       {
        super.Tick(DeltaTime);
       }
    
       
       function UpdateDragLocation(vector NewDragLocation)
       {
        Pawn.SetPhysics(PHYS_Flying);
      
      //只要被拖拽那就停止状态  
        if(VSize(currentDragPoint-NewDragLocation>100)
        StopLatentExecution();
      
      //目前的位置和被拖拽位置是一样的。  
        currentDragPoint=NewDragLocation;
       }   
    }

    然而ChickenController_Chicken中也存在State Grabbed。不过暂时没什么重要内容。重要的地方在于AIController_Fox中,进入其State DragPrey。Tick函数

    event Tick(float DeltaTime)
    {
     local vector newloc;
     local rotator newRot;
    
     //这里是最重要的,拖小鸡
     if(currentGrabbedPrey!=none)
     {
      GetCarryPosition(newLoc,newRot);
      Interface_DraggableItem(currentGrabbedPrey).UpdateDragLocation(newLoc,self,true,newRot);
     }
    
     super.Tick(DeltaTime);
    
    }
  • 相关阅读:
    二维莫队的一个细节
    错失AK良机的测试48T3 Walk
    枚举二进制子集
    又是一次值得纪念的考试
    测试46
    值得纪念的测试43
    点分治模板理解
    牛客多校第三场 G Removing Stones(分治+线段树)
    牛客多校第三场 F Planting Trees
    HDU6621 K-th Closest Distance HDU2019多校训练第四场 1008(主席树+二分)
  • 原文地址:https://www.cnblogs.com/NEOCSL/p/2764222.html
Copyright © 2020-2023  润新知