- Home /
Shooting Enemy AI with Patrol
Hi everyone I am doing a FPS game. I need a enemy ai, when enemy see the player he should shoot at him and start follow him and when the player is not there he should patrol. I am new to unity and c# so please put the script and animator controller of the enemy Pls!!! Thanks in advance :)
Answer by HellsHand · Apr 07, 2021 at 01:24 PM
If you are new to Unity and coding I would highly recommend you find some tutorials on the web. Though some may be glad to just drop some code for you, you will never learn that way and will find yourself back here for every problem you face. Along the lines of the old proverb "Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for life".
I already referred web regarding enemy ai but there are tutorials based on melee enemy ai but I need a shooting enemy ai if you know some tutorials regarding shooting enemy ai pls share it to me. Thanks @HellsHand
Here is a quick and rather simple tutorial for following and shooting at a player: https://www.youtube.com/watch?v=db0KWYaWfeM. It may seem like I'm being a jerk but I've spent years in diagnostics and have learned that the more accustomed to finding information you become, the easier it will be for you in the end. Sometimes you may be stuck for hours/days waiting for someone else to answer a question or give you the information. Hope this helps and good luck in your adventures in program$$anonymous$$g =).
Answer by singhlaxman9761 · Apr 08, 2021 at 12:16 PM
Use collider to detect player collision detection with specific distance (Collider size "x,z" axis) and make sure is player detect then check raycast hit between player and enemy, is there any other object exist in between then dont shoot otherwise shoot.
Code to check is there player raycast or not:
if (Physics.Raycast(playerCamera.transform.position, playerCamera.transform.forward, out hit, 200))
{
if (hit.transform.CompareTag("Player"))
{
Debug.LogError("Shoot player!!!");
}else
{
Debug.LogError("Dont Shoot");
}
}