【问题标题】:applying direction to npc XNA向 npc XNA 应用方向
【发布时间】:2013-12-11 09:40:40
【问题描述】:

我的游戏中有 NPC,它们遵循脚本在游戏中随机移动。不过,我希望他们正视他们前进的方向。

for (int i = 0; i < GameConstants.NumDaleks; i++)
{
    if (dalekList[i].isActive)
    {
        Vector3 line = dalekList[i].direction;
        float rotationDal = (float)(Math.Atan2(dalekList[i].position.Y, dalekList[i].position.X) / (2 * Math.PI));

        Matrix dalekTransform = Matrix.CreateScale(GameConstants.DalekScalar) * Matrix.CreateRotationY(rotationDal) * Matrix.CreateTranslation(dalekList[i].position);
        DrawModel(mdlDalek, dalekTransform, mdDalekTransforms);
     }
}

我确定这一定与rotationDal有关,我已经尝试更改计算并且字符似乎确实以不同的方式旋转,只是不是在他们当前的方向

【问题讨论】:

    标签: c# matrix xna rotation


    【解决方案1】:

    Xna 有一个内置函数,您可能会在这里找到方便。

    Matrix.CreateWorld(positionVector, DirectionVector, UpVector);
    

    这是文档:http://msdn.microsoft.com/en-us/library/bb975261(v=xnagamestudio.40).aspx

    在你的情况下:

    for (int i = 0; i < GameConstants.NumDaleks; i++)
    {
        if (dalekList[i].isActive)
        {
            Matrix dalekTransform = Matrix.CreateScale(GameConstants.DalekScalar) * Matrix.CreateWorld(dalekList[i].position, dalekList[i].direction, Vector3.Up);
            DrawModel(mdlDalek, dalekTransform, mdDalekTransforms);
         }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      相关资源
      最近更新 更多