开发者

Approach to coding a lot of different AI's?

开发者 https://www.devze.com 2023-03-18 12:15 出处:网络
I\'m currently working on a game. There will be quite a few different AI\'s, one for every enemy. How do I go about implementing this? Do I make a base class, from which I derive开发者_高级运维 a cla

I'm currently working on a game. There will be quite a few different AI's, one for every enemy.

How do I go about implementing this? Do I make a base class, from which I derive开发者_高级运维 a class for every single type of AI? Do I just make one big class, with all AI's in a select case? Maybe something else?

I'm doing this in Unity3d with C#.

Thanks!


Well I guess it depends,

There a plenty of ways of doing this.

1) Classical OOP, you can make a detailed class structure deriving from AI interface, and then work your class hierarchy from there.

2) You could use component oriented design, then create an AI component, which can be initialized and further expanded using different smaller components.

3) You can go the scripting route, scripting outside of your "Engine" your AI logic, this is nice because it offers separation between the core engine functionality and your particular game Logic.

In my opinion it certainly depends on your particular needs, I often Mix 1 && 3, but I guess you could go with 1 || 2 || 3, they are not totally exclusive.

I think another thing you should have in mind is your character control system and how you have implemented that, the character control system will have a direct impact in how you will implement your AI system architecture.

Good luck :)


Maybe design pattern "Strategy pattern" fits your needs. See wiki page.

  • It forces you to use similar interface for every AI.
  • It allows you to change AI algorithm of an enemy object at runtime.


A safe way to begin designing something like this is to create a unit AI interface, then place each AI into a separate class implementing it. Common functionality could be placed into helper classes.

In regards to object hierarchies, game AI should follow SOLID principles, as everything else.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号