Physics 2D Raycast is not working

I have a basic enemy that is supposed to move towards the player when the raycaster collides with the player. I have been at it for a couple of days and cannot figure out what I am doing wrong. Here is the code I have written.

void Update () {
RaycastHit2D hit = Physics2D.Raycast (transform.position, transform.localScale.x * Vector2.right, sight);
if(hit.collider != null && hit.collider.tag == “character”){
GetComponent ().AddForce(Vector3.up*force + (hit.collider.transform.position-transform.position)*force);
Debug.Log (“Player nearby”);

}

}

The debug log is not doing anything either and no matter what I change the tag to or if I even take the tag off it is not doing anything. Any help at all would be greatly appreciated!

Yes, I have a collider on it and it is active. My player walks around and collides with the ground and other triggers, but the raycast coming off of this enemy is not detecting the player. I tried setting the tag to a different object and it detected that, but no matter what I have tried it will not detect my character.

there are very many reasons that can make raycast not work as you wish, you should:

1st Debug when Hit.collider not null the name of hit.collider.gameobject

2nd, Check the position of Enemy on Editor, maybe it’s lower than Player Collider

3rd, you use vector2.right as direction, you can try ignore local Scale, only vector2.right and watch if its work? (im afraid something local scale x not = 1).

4th, you should use layerMask for only find Player, the raycast only find 1 Hit, the nearest hit, that mean if the nearest hit not have Tag == Player, youre fail

in case you wanna find many Hit, use raycastall

If you click the output icon, then your print, debug.log etc… Should show on the Console Output Window. Window > General > Console. I hope this would help cause this solved my issue with raycast not displaying on Console Window.
136809-console-output-example.png