zoukankan      html  css  js  c++  java
  • 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);

      
    }



     

  • 相关阅读:
    窗口吸附
    c++中冒号和双冒号的用法
    C++Builder中注册表的操作
    C++ Builder VCL库函数简介
    C++ Builder 2007中应用数据库SQLite(转载)
    如何使用C++获取 进程的 绝对路径
    正则表达式入门
    为什么要用 C# 来作为您的首选编程语言
    CSharp交换函数swap的三种实现方法
    告别码农,成为真正的程序员
  • 原文地址:https://www.cnblogs.com/NEOCSL/p/2366785.html
Copyright © 2011-2022 走看看