Check if there is something in the left side or right side. How?

hi, i want to check if there is an enemy in the right side of the player but i don’t know what should i use to do this . thnx.

1 Answer

1

Math. You should use math. :wink:

var target : Transform; // da Target

function CalculateDestination () { // Calculate the Angle to the Destination

	var destination = transform.InverseTransformPoint(target.position); // Converts Location for use
	destinationAngle = Mathf.Atan2(destination.x, destination.z) * Mathf.Rad2Deg;  // Calculates the Angle and Converts from Rads to Degrees
	destinationDistance = Vector3.Distance(transform.position, target.transform.position);  // Determine Distance between this Object and the Destination

} // END Calculate Destination Angle

Now, all you need to do is check the angle and there ya go. From now on though, please
attempt to solve your problems and post your code if you are having issues. Blanket questions like this are typically ignored.

Be specific and put context into your question as much as possible so we can understand how you are defining your ‘player’, your ‘enemy’, etc.