- Home /
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.
Answer by AngryMarine · Aug 29, 2011 at 01:58 AM
Math. You should use math. ;-)
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.
Your answer
Follow this Question
Related Questions
Flip an object by 180° (C#) 0 Answers
how to get a correct rotation 2 Answers
Track object rotation 1 Answer
Paint the angle of AI 1 Answer
Raycast at angles 1 Answer