Auto aiming turrets

How do I make a turret automatically aim for the nearest target, but, if aiming at their own parent not to be able to fire?

As well as this, how would I make a missile follow a target or a small spaceship follow, but also variate around them, not just staying behind?

you should try the tornado twins tutorials, alot of this is covered. :stuck_out_tongue:

also if you dont want it to aim at their own parent possibly add differnt tags for targets and non targets :smile:

To answer the first question, create a new tag called something like “EnemyTarget.” Assign this tag to all enemy targets that the turret should be targeting, add them to an array and loop through every object, checking which one is closest. I’m assuming that’s basically what you want to do, but if you just want to check if it’s a parent or not, you can just do

if (target.transform != transform.parent)
{
//FIRE FIRE FIRE!
}

This just checks if it’s targetting the parent. I can go into a little more detail in the first response if you need more help…if you’re fairly new to either scripting or Unity I can see how it might be a little confusing.

The second question is a bit vague, and my answer would depend mostly on exactly how you want the missile to move.