I am still pretty new with coding C# and Unity development, so I realize that some of the answers to my question might go over my head. However, I thought it would be a good idea to get some feedback from you guys before I went much further with my mobile game project.
As the title of my post indicates, my question is about optimizing the AI in my games so that it doesn’t negatively impact the game’s performance on mobile devices.
At the moment, this is the code that I am using for my AI:
using UnityEngine;
using System.Collections;
public class BasicAI : MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
private Transform myTransform;
void Awake ()
{
myTransform = transform;
}
// Use this for initialization
void Start ()
{
GameObject go = GameObject.FindGameObjectWithTag ("Player");
target = go.transform;
}
// Update is called once per frame
void Update ()
{
//Look at target
myTransform.rotation = Quaternion.Slerp (myTransform.rotation, Quaternion.LookRotation (target.position - myTransform.position), rotationSpeed * Time.deltaTime);
//Move towards target
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
For anyone interested, this code came from BurgZurg’s YouTube Channel:
I would imagine that a single instance of this “AI” script would not cause any performance issues on mobile devices.
However, my current plan is to have 20-30 “Enemy units” all using this AI script at the same time, in order to target and attack the “Player.” I have read that Unity’s Update function is resource intensive, so I am concerned that if 20-30 instances of this “AI script” are all using the Update function simultaneously , that my game will suffer a huge performance hit. This is an especially big concern, given that this game will be running on mobile platforms.
This leads to several questions, which I hope that you guys can help answer:
1.) Should I be concerned about a performance hit while using so many instances of this script? Or do you think mobile devices will have enough processing power to make this a non-issue?
2.) Is there any way I can check to see how such a game would perform on mobile without a Unity Pro license?
3.) Is there a better way to set up an AI system in my game that would be less resource intensive?