- Home /
enemy ai going to player
im doing a fps with the fps tutorial but i whant to add a new enemy. the one i whant to add is a cube that try to run into the player when it get in range and when it hit him it get replace by a explosion that will damage the player. i know how to make the cube by an explosion when it hit the player but i dont know how to make the AI. plz help :)
Answer by kennypu · Apr 14, 2011 at 12:29 AM
well if it can be really simple, you can do something like: if(Vector3.Distance(player.transform.position,enemy.transform.position) < certainDistance)</p> <p>{</p> <p>enemy.transform.position = Vector3.MoveTowards(enemy.transform.position,player.transform.position,speed);</p> <p>}
certainDistance is a distance obviously. speed is the speed of the enemy. should be Time.deltaTime * 10 or something like that if you want it to always have the same speed.
Answer by chrismisballs · Apr 14, 2011 at 12:29 AM
"Berg Zurg Arcade" google it, they have hundereds of tutorials on this kind of stuff also youtube "basic ai in unity" that will help also. Good Luck
Your answer
Follow this Question
Related Questions
AI Script attached to Enemy and is Rotating around player 0 Answers
Enemy controller.move script slows down and speeds up. How to get it consistent? 0 Answers
Bug with my enemyAI 2 Answers
Monster Patrolling 1 Answer
Need help with AI script 1 Answer