
It looks like you're new here. If you want to get involved, click one of these buttons!
Hi I am new to unity and if you know how to add shooting enemy AI in unity 3d please help me out!!!
Any Help will be appreciated!!
Thanks
in the update function you can do
Collider collide = Physics.OverlapSphere(enemy.position, sphereSize, whatIsPlayer);
if(collide = null) //if the player isnt in it's 'bubble'
{
InvokeRepeating("Shoot", 2f, shootRate);
transform.LookAt(player.position, vector3.up);
} else
{
CancelInvoke();
transform.LookAt(-player.position, vector3.up);
}
in the else you can make it run away
Answers
@Sugar_Snail Thanks a lot!!
what , can you make the full script ?
@nio2edward
I made the whole thing on my own
For the shooting enemy AI use this script
BTW the player Cube GameObject here is just a cube as child of player without mesh renderer & collider to reduce shot accuracy
if you want 100% shot accuracy just drag your player into that
Attach this script above on your my and add an empty gameObject where you want your enemy to shoot from (GunTip in this script) Ad the script bellow to your empty gameObject
Ad the script below to your player