首页 文章

Unity Pathfind简单的AI

提问于
浏览
1

我在Unity中编写了一个简单的游戏,我需要帮助一些简单的AI用于敌人 .

我有三个GameObjects: BackgroundPlayerEnemy . 所有这些对象都有一些精灵,刚体等 . 背景包含Box / Circle Colliders . 按W / S / A / D可以移动玩家 . 我需要JS中的简单脚本来允许敌人跟随玩家(使用路径查找) . 我尝试过类似的东西,但出了点问题:

var agent: NavMeshAgent = GetComponent.<NavMeshAgent>();
agent.SetDestination(targetPoint);

什么都没发生...

有什么帮助吗?

1 回答

  • 1

    这是我在敌人运动中使用的一个非常基本的片段,我将其置于运动脚本的Update()函数中(记住C#):

    Vector3 direction = Vector3.Normalize(transform.position - destination.position);
    transform.position = Vector3.MoveTowards(transform.position, destination.position, moveSpeed * Time.deltaTime);
    

    我希望它可以让你的敌人四处走动!

相关问题