# how do i include enemy's rotation within my checking of if player is on the right side of enemy?

Okay (problem in code is at line 61 thru 86)
the code is basicly checking if player is within a certain distance if so, then enemy will turn (within a time frame) towards player.

The Problem:
When enemy rotates towords player the game still reads that the player is still on the right side of enemy. however, as you can see in the photo, the player is actually standing right in front of the enemy.

My Question:
How can i make sure that when the enemy rotates that the game also reads the player’s position correctly. meaning when the enemy rotates to face the player the game knows that the player is no longer standing on the right side of enemy but instead is now standing infront of enemy?

What I am trying to accomplish:

so the enemy is minding it’s own business. however, when the player comes to the enemy then the enemy will react correctly based on which side the player is on.

[[ clarity ]]:

player sneaks up on left side; enemy jumps to right and runs.
player sneaks up on right side; enemy turns towards player and attacks.
etc…

The photo shows both the code and the problem issue. (in the editor within the picture the enemy has already rotated towards the player. but the game is still reading the player as if they are on the right side of enemy still). [you can right click on image and open in new tab to get a high resolution of the image and read everything clearly]
vars:
target = player transform
pposition = player position
eforward = enemy’s forward direction

The problem is this line here

``````if(target.position.x > transform.position.x && target.position.x < (transform.position.x + 10)){
``````

You are checking if the GLOBAL position of the player is in the GLOBAL x direction, which does not at all take into account the rotation of the enemy unit. There are 100 different ways that you could do this, but we might as well use similar code to what you are already doing using the dot product. Notice that I am removing the y component of these vectors, just to make sure the calculation ignores any weirdness in the vertical axis.

``````Vector3 rightFlat = transform.right;
rightFlat.y = 0;

Vector3 targetDirectionFlat = target.position - transform.position;
targetDirectionFlat.y = 0;

if(Vector3.dot(rightFlat, targetDirectionFlat) >= 0){
//Player is to the right
} else{
//Player is to the left
}
``````