O'Reilly logo

Unity 4.x Game AI Programming by Thet Naing Swe, Aung Sithu Kyaw, Clifford Peters

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

AI character

Our AI character will be roaming around the scene in a random direction. It'll have two senses: perspective and touch. The perspective sense will check whether the enemy aspect is within a set visible range and distance. Touch sense will detect if the enemy aspect has collided with the box collider, soon to be surrounding our AI character. As we have seen previously, our player tank will have Enemy aspect. So, these senses will be triggered when they detect the player tank.

The code in the Wander.cs file can be shown as follows:

using UnityEngine; using System.Collections; public class Wander : MonoBehaviour { private Vector3 tarPos; private float movementSpeed = 5.0f; private float rotSpeed = 2.0f; private float minX, maxX, minZ, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required