Aim and than shoot

I made some turrets for my game, each one can find me and it will start shooting when I get into it’s shooting range.

The problem is that the turrets are shooting even if it not “aming” on me, it will shoot as long I’m in it’s shooting range: for some the damping speed not allow them to always aim on me and it take some time untill thay are “realy aim” (it have to be like that), but thay will continue to shoot because the distance between me and the turrets allow it. The turrets will continue to shoot even if there is an obstacle like a wall or another turret between us from the same resone.

How do I make the turrets shoot only if thay are aming at the general direction (for missing chances) of me and when there is no obstacle between us?

Follow the syntax showed below…

Physics.SphereCast(/here fill as per your requirement/);

This is the simple way for your need…Cheers…Enjoy…If found useful Don’t forget to mark…

Use Physics.SphereCast. Set the radius to be your auto aim error, distance to be the range of your turret.

		//Ray should be configured with the turrets position and whatever 
		//direction it is currently pointing (assuming Vector3.forward).
		Ray = new Ray(turretRange.transform.position, Vector3.forward);
		if(Physics.SphereCast(ray, autoAimError, hitInfo, turretRange)) {
			//There are various ways to tell if this is the right collider.
			//Here we will use the tag of the object we want to hit.
			if(hitInfo.collider.gameObject.tag.CompareTo("target")) {
				//The sphere cast hit the target. Shoot.
			else {
				//The sphere cast missed the target. Don't shoot.