- Home /
Hi? I am only a beginner on using unity 3d. I wonder how to create an enemy AI that moves randomly on a specific place?
the 3d game that i will develop is the same as the game Battle City that often we play on a family computer. just need some help on making enemy tank AI to move randomly. Every answer will be very much appreciated. Thank you. :)
Answer by Graham-Dunnett · Nov 19, 2013 at 12:03 PM
One solution would be to use the NavMesh feature in Unity. You can then give your agent a randomly chosen destination with the `SetDestination` API.
Thanks. But in my condition, this game that i will develop will be past on friday. Actually, this is a school project so i have to finish it as soon as possible. Is there's any way or a script you can give to me sir?
Answer by Sylafrs · Nov 19, 2013 at 02:30 PM
If you want a really stupid AI :
you need some functions such as : GetRandomDirection, MoveForward and some variables such as : MinTimeBeforeChangingDirection, MaxTimeBeforeChangingDirection, Speed
If you want something more nice :
Check NavMesh, NavMeshAgent, and instead of getting a random direction, get a random Transform point within a list of positions that your agent could need to go.
(if your map is an 'house', or something complicated)
You can also mix these two solutions :
Get a random position then ask your agent to go there, using the navmesh. Once he finished, do it again :p
(if your map is a cube)
Happy coding :)
Your answer
Follow this Question
Related Questions
Animating Tank Treads 0 Answers
fire tank in any direction 1 Answer
Multiplayer projectiles collision 0 Answers
player on trigger enter dont work? 1 Answer