C# or Javascript for enemy AI
I'm sorry if this has already been answered, but I could not find this anywhere in the forums. I have been working on a game in Unity and will be starting on enemy AI soon. My question is which language (of C# or Javascript) is better for my game. When I say "better" I am talking about a few things, mostly overall speed, loading time, hard disk space, and functionality (easy to fix bugs/glitches, easy to do more complex things in less time, etc.) I am somewhat new to Unity and C#, but I know very little about Unity's version of Javascript. My game is a top-down 3D rpg. Most models are very simple and should not effect speed very much. The battle system for which I will use this AI and the AI system itself are somewhat complex, and will not be turn-based. I use Unity Personal Edition version 5.3.2f1 64-bit on a 64-bit PC.
Thanks in advance.
Answer by ericbegue · Jul 05, 2016 at 07:37 AM
Both C# and JavaScript (aka UnityScript) are compiled to CIL bytecode. So, the difference is only a matter of syntax; both languages should be equivalent in terms of speed and memory usage. Which language to choose depends on your own preference (or the preference of your team).
If you are new to Unity, I would suggest to go for C#. Since it is the most used language, you will be more likely to find online examples and help from other users. Also there are rumors that UnityScript might not be supported in the future, but there is no official announcement about that.
About writing AIs, both languages are general-purpose and does not provide specific AI functionalities. So, the language choice is irrelevant when it comes to AI. Rather, you would need to learn about AI techniques or methodologies.
Here are some techniques you might want to look up for:
Finite-State Machines
Decision Trees
Behavior Trees
Hierarchical Task Networks
Utility Systems
I am a Behaviour Tree enthusiast and developed a script-based framework based on this technique, you might be interested to have a look at Panda BT.
Also Unity has built-in support for navigation and pathfinding. You can use this system to make your character models be aware of their environment and make them move from a point A to a point B by finding the shortest path and by avoiding obstacles.
Answer by FeeeshMeister · Jul 05, 2016 at 03:56 PM
How do I comment and show your answer is correct?
You have the "Accept" and "Add comment" buttons at the bottom of the message.
Thanks, I'm new to the Unity website as well.
Your answer
![](https://koobas.hobune.stream/wayback/20220612084236im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Save system 1 Answer
How do I make a enter and exit car script? 0 Answers
Custom Camera Script Toggle Enabled / Disabled 2 Answers
Trying to make a Parkour Platformer! 0 Answers