• 3:《地牢守卫者》代码分析:PlayerPawn


    玩家具备一个替换武器的功能,基本方法就是销毁前一个武器创建一个预期的新武器。

    function SwapWeaponFor(AntWeapon WeaponTemplate)
    {
    if(Weapon!=none)
    Weapon.LifeSpan=-1;
    Invmanger.RemoveFromInventory(Weapon);

    if(weaponTemplate!=none)
    CreateInventoryFromtemplate(WeaponTemplate);
    }

    将武器的生命周期设为-1,同时从模板中将其清空。

     skelControlLookAt骨骼观察目标。

    ConvertDegreeFloatToRotAxis将float转化为角度

    获取一个目标点的方向

    function GetTargetRotation(vector TargetLocation)

    {

      local rotator TargetRotation;

      TargetRotation=Rotator(TargetLocation-Location);

      DesiredLookAtYaw=Clamp(TargetRotation.Yaw-Rotation.Yaw,ConvertDegreeFloatToRotAxis(-52),ConvertDegreeFloatToRotAxis(52)); //取一个角度范围
    }

    获取了方向后应该在Tick中进行插值运算

    event Tick(float DeltaTime)

    {

      super.Tick(DeltaTime);

      CurrentLookAtYaw+=float(DesiredLookAtYaw-CurrentLookAtYaw)*FMin(DeltaTime*5.0f,1);

      PlayerSkelControlLookAt.BoneRotation.Yaw=CurrentLookAtYaw;
    }

    上面的Tick函数一直执行了一个枚举,遍历场景中的金币ManaToken,CheckForTokens()。其实Tick加枚举是最影响性能的因素,以后有机会我再优化方法。

    var float ManaTokenAttractionRadius;   //吸收的距离,这让我想起了奎爷吸魂;)

    var float ManaTokenCollectRadius; //拾取的距离

    function CheckForTokens()

    {

      local AntManaToken Token; //在使用遍历的时候应该牢记一点,要遍历局部变量是必备的,这应该在以后写的时候构成条件反射

    foreach OverLappingActors(class'AntManaToken',Token,ManaTokenAttractionRadius)

      {

        token.AttrackTo(self); //这将是大名鼎鼎的吸魂魔法  

        if(VSize(location-Token.Location)<ManaTokenCollectRadius)

        AntPlayerController(controller).CollectManaToken(token); //token.Collected(AntManaToken token); AddManaPower(token.ManaPower);

      
    }



     

  • 相关阅读:
    面向对象(Object Oriented)
    文件操作
    函数
    dict--字典
    list--列表
    Ubuntu_18.04安装网易云音乐
    初识数据类型
    css控制内容显示,自动加"..."
    css固定元素位置(fixed)
    解决IE下iframe默认有白色背景的bug
  • 原文地址:https://www.cnblogs.com/NEOCSL/p/2366785.html
Copyright © 2020-2023  润新知