游戏邦在:
杂志专栏:
gamerboom.com订阅到鲜果订阅到抓虾google reader订阅到有道订阅到QQ邮箱订阅到帮看

简述AI转向行为的概念及用处

发布时间:2014-07-29 11:25:45 Tags:,,,

作者:Juan Felipe Belon Perez

引言

AI仅仅是AI吗?

它们在一片充斥大量角色的土地上平静地行走,追捕你或者只是在巡逻的时候看守一扇门,这不禁令人发问:“这些实体到底在想些什么?”

watch-dogs-npc-profiles(from gamasutra)

watch-dogs-npc-profiles(from gamasutra)

“这些实体到底在想些什么?”

我对这类问题一直很感兴趣,也很佩服有些AAA游戏AI能够避开障碍,在毫不费力的情况下躲过枪林弹雨并准确无误地找到你的位置。所以我开始学习关于复杂AI的一切:移动,行为,训练等。我的AI不仅仅是想成为只会撞到墙壁的简单僵尸!

这就是我的想法。

但,什么是基于转向的AI行为呢?

figure1(from gamasutra)

figure1(from gamasutra)

它是一个实体如何决定自己在空间中的移动,如何与你和其他游戏元素互动的方式。简而言之,就是它如何在你的世界中生存!首先出现在我脑海中的这种概念图是《模拟人生》的非玩家角色。它们当然具有确实很复杂的行为树。

有时候你无法直接插入一个角色就指望它立即生效,你必须训练它,并且你可以使用ORTS等软件来执行这一操作,这是用来创造角色技能与游戏实体之间的平衡,例如战略或塔防游戏就是如此。你还可以使用基因编程来进化AI行为。

为什么是转向行为?

这些东西都很棒,但对于我的动物放牧游戏来说,我需要一些不同的操作。我去年制作的首个原型只能使用一个简单的近似行为:每只小羊都有一个目标节点,它们在受到牧羊犬的恐吓之前会使用一个简单的力向量来跟随它,在受到惊吓之后它们会改变目标。从视频中可以看出,它们无法看见彼此,也并不像我所期望的那样出现群体性的行为。我的研究就由此开始,并因此突然发现了我真正所需的东西。

“自主性角色是一种用于电脑动画和交互媒体(如游戏和虚拟现实)的自主性代理类型。这些代理代表故事或游戏中的一个角色,并且拥有一些即兴行为的能力。它与事先编写好动作的动画片角色,以及游戏或虚拟现实中由人类或参与者实时操纵的“虚拟角色”形成鲜明对比。在游戏中,自主性角色有时也称为非玩家角色。

自主性角色必须包含拥有一些人类即兴表演技能的自主性机制,这些角色通常不是真正的机器人,当然也不会是人类演员,但却兼具这两者的一些属性。”

你可以将转向行为用于:

*赛车游戏AI:沿着路面行走的汽车,或者跟随指挥的轮船。

*任何使用导航AI的游戏:RPG中的NPC,动作游戏角色:A* 和循径转向行为。

*含有AI行为的游戏需要:结群、漫游、追逐和逃避、寻找等行为。

转向行为并不会消耗太多CPU,所以你可以放心地在手机游戏中植入这一设置。

一个简单的例子

这是来自全局视野的一个转向行为。

figure3(from gamasutra)

基于OpenSteer框架(from gamasutra)

每个行为代表一个力向量。通过让向量比例更大,赋予其更多权重,可以让实体往这个力行为的方向移动。例如,将玩家设置为寻找者,这样你就可以让实体角色遵从一个方向,然后添加一个将躲避狼实体的羊实体。现在为羊添加一个跟随某个地点的漫游力,这样你就可以得到以下图表:

Steer_3(from gamasutra)

Steer_3(from gamasutra)

你可以从ShiVa维基页面ShiVa Steering下载这个样本。

我为什么要选择ShiVa引擎呢?——你可以用Lua编码,并用C++输出游戏,它极其有效,所以我可以在低配置设备上以较好的帧率运行超过15个实体的复杂行为。

它如何运行?

在这个例子中,我们用每个鼠标事件更新了玩家实体即寻找者的目标地点。因此这个实体最重要的力就是寻找函数。我们使用物理引擎和一个半球碰撞器来作为动态基础。

逃跑的实体想找一个可以避开追捕者的地方。所以逃避函数就是它们最重要的力。而追捕者则试图接近目标实体。

数学

首先你得实现实体的转变,然后计算向量和方向以获得下一个力的向量。查看其距离是否大于半径,令向量标准化,并以一个比例限制设置每个实体的新速度。

当你合并所有力并设置新速度后,角色就会遵循行为动作。(本文为游戏邦/gamerboom.com编译,拒绝任何不保留版权的转载,如需转载请联系:游戏邦

Introduction to Steering Behaviours

by Juan Felipe Belon Perez

Introduction

AI’s just wanna be AI’s?

In a land full of chars walking placidly, hunting you or just guarding a door while patrolling, there is this question in the air: “What is this entity thinking ?”.

“What is this entity thinking?”

I was always fascinated with this kind of question, and I loved how some AAA games AI’s were able to avoid obstacles, find and reach your position while dodging bullets without any trouble. So I began to learn everything about complex AI’s: movement, behaviours, training, etc. My AI’s must want to be more than a simple zombie bumping into or hitting walls!

- That is what I thought -

Wait, what is an Artificial Intelligence Behaviour based on Steerings?

It is the way an entity decides how to move in the space, how to interact with you and other game elements. In short; how to live in your world! The first conceptual picture of this that appears in my mind is the Non Player Characters from the Sims. They sure have a really complex behaviour tree. If you want to know more about this, check “Behavior trees for AI: How they work”.

Sometimes a char AI can’t be plugged and start working, you need to train it, and you have software like ORTS to do such things, this is used to create a balance between player skill and the game entities, for example for strategy or tower defense games. You also can use genetic programming to evolve AI’s to what you really want like this genetics cars based in Box2DCar.

Why Steering Behaviours?

All this stuff is great, but for my animal-herding game I needed something different. The first prototype I made last year only used a simple approximation behaviour: each lamb has a target node, they follow it using a simple force vector while they are waiting for the dog to scare them, and once scared they just change the target. As you can see in the video, they are not seeing each other, they dont act like a flock as I wanted. The research was just about to begin with this when the world opened in front of me and suddenly I found the exact thing I needed.

“Autonomous characters are a type of autonomous agent intended for use in computer animation and interactive media such as games and virtual reality. These agents represent a character in a story or game and have some ability to improvise their actions. This stands in contrast both to a character in an animated film, whose actions are scripted in advance, and to an “avatar” in a game or virtual reality, whose actions are directed in real time by a human player or participant. In games, autonomous characters are sometimes called non-player characters.

An autonomous character must combine aspects of an autonomous robot with some skills of a human actor in improvisational theater. These characters are usually not real robots, and are certainly not human actors, but share some properties of each.”

Steering Behaviours by Craig W. Reynolds, this is the real thing,and it can manage flocks! (well, it can manage whatever you want, even just a simple entity with different behaviours)

You can use Steering Behaviours for:

A racing game AI: automated vehicles following the road, or ships that follow a leader

Any game that uses navigation AI: rpg npcs, action game chars: A* and Pathfollowing Steering Behavior

A game with AI behaviours needs: flock, wander, flee, pursuit and evade, seek, etc

Steering behaviours can be very cheap for cpu usage, so you can integrate it without worries in mobile games.

I implemented my first version of Steering Behaviours for moving enemies

In the game The Legend Of Kuzu, this was only a flocking with avoiding collisions and simple seeking.

A Basic Example

This is a steering behaviour from a global vision/view

Based on OpenSteer framework.

Each behaviour is represented as a force vector. Giving more importance to one or another by making the vector scale bigger, makes the entity move in the direction of this force-behaviour. For example, set the player as a seeker so you can have the entity char follow a position and then add an entity that is a sheep that will evade wolves entities. Now set an evade force for the sheep and a pursue force for the wolves, you may want to add a wander force to make the sheep follow a location, then you will have a diagram like this:

you can download this sample from the ShiVa wiki page: ShiVa Steering.

Why did I choose ShiVa engine? – you can code in Lua and export the game in C++, it is so efficient that I can run complex behaviours with more than 15 entities in an low-spec device with a good framerate.

This is the example running:

How it works?

Well, in this example, we are updating the target location for the player entity, which is a seeker, with each mouse event. Therefore, the most important force for this entity is the seek function. We use the physics engine and a sphere collider as the dynamics base.

The fleeing entities watch for a place away from pursuers using rays. So the function evade is the most important (greater vector scale magnitude) for these (also they are not using seek but wander). The pursuers, are trying to reach the targets entities.

A more elaborated example with chars, animations, sfx and some art:

Maths:

First you get the translation of the entity, then compute vectors and directions to get the next force vector. Check if distance is greater than radius, normalize and scale the vectors and set the new velocity in the scale limit for each entity.

Once you sum all the forces and set the new speed, the character will follow the according behaviour of movement.(source:gamasutra


上一篇:

下一篇: