• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
AniMerrill

AI in Unity: An Abstract Approach?

3 posts in this topic

[b]NOT ANOTHER "PLEASE GIVE ME AN AI TUTORIAL POST"[/b]

(mostly)

I am designing a game in Unity 3d, and this is a question to all the designers out there that have also chosen this development tool specifically (although I'd appreciate help from anyone).

I've never done AI for enemies before. I get the basic concepts though, and I think I could learn the more advanced algorithms for pathfinding and yadda yadda with enough study of the subject, since there is a LOT of documentation about it. My question is more like: what are the best practices for approaching character AI in a game, especially if you're using Unity?

Because of the way Unity works, I more or less want to create a "Behavior" object to attach to any character using AI. This would basically be a script or whatever that would behave a lot like a Player controller, but instead of taking conroller input, it would obviously act based off pre-programmed behaviors. Now obviously, not every character will behave the same way. Some enemies will be very stupid and wander aimlessly, others will try to more directly attack the player, and some might even be ally characters who need to respond to the player in distress.

What I want to do is have it so that every instance of this "Behavior", I guess you'd call it, "class" attached to these characters to be loadable with specific behaviors. That way I could have a modular list of behaviors that can be added and subtracted from a list and greatly change the way an AI controlled character will behave.

My question is this best practice? If not what is? And if so, what would be the best way to go about this in Unity so that it is as modular as possible to allow for high customization?

This is sort of an abstract question, and therefore only really expect abstract results unless if someone can point me to a tutorial where maybe this sort of thing is demonstrated. Thanks!
0

Share this post


Link to post
Share on other sites
I'm also using Unity, and currently working on my game's AI. It's a space game, and each ship has a controller behavior. It contains the methods that allow for basic movement such as set throttle forward, or turn to the right. For the player, it listens to input and reacts accordingly. For ai, it doesn't listen to input, and a separate AI behavior calls the movement methods directly. I plan on making the AI contained in a single script, with modifiable variables and settings represented by enums to vary behavior. I'm not sure how using separate behaviors would work, unless all they did was modify variables in the master AI script. Unless you're talking about AI with completely different behavior (e.g. turret vs pac man ghost), then it would seem you just need a completely different script for each one.

I'm not really sure what "best practice" would be in this case, though. I imagine your exact needs really change what the best solution is.
0

Share this post


Link to post
Share on other sites
You could also have a base class that does a lot of the mundane stuff that other classes inherit from (in addition to the Unity Behavior class). Then, each type of character could be assigned the script appropriate to its specific needs. However, if there is similarity between then, the enum + parameterized approach works well, too.
0

Share this post


Link to post
Share on other sites
I start with a basic state machine, which I got from the hack n slash tutorials, called AI, and add additional states for all the activities I want.

[CODE]
using UnityEngine;
using System.Collections;
[RequireComponent (typeof(AdvancedMovement))]
[RequireComponent (typeof(SphereCollider))]
public class AI : MonoBehaviour {
private enum State {
Idle, //do nothing
Init, //make sure that everything we need is here
Setup, //assign the values to the things we need
Search, //find the player
Attack, //attack the player
Retreat, //retreat to spawn point
Flee //run to the nearest spawn point with another mob
}
[/CODE]

It requires my character controller script and a sphere collider to check a perception radius. If the player enters the perception radius, the state machine starts searching for a target and moving towards it. If it gets close enough, it enters an attack state which triggers an attack function. You can get as complex as you want within the state. Your move() function can use whatever pathfinding you want, a*, or basic trig.

I'd check out the actual tutorial: [url="http://www.burgzergarcade.com/hack-slash-rpg-unity3d-game-engine-tutorial"]http://www.burgzerga...engine-tutorial[/url] tutorials 103-105 are the basic movement and ai if the player enters the perception radius, but runs too far away, the target reverts back to the spawn point, if the player re-enters the perception radius it becomes the target. For the flee you have to store the location of other spawn points.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0