get RaycastAll return true when hitting colliders on them

is there any way getting the raycast return true when im instantiating the raycast on a vector that is the point where the collider i want it to check?
(i have added a picture down)


i have an enemy i want to check if its close enough in order to attack it.
so it works if im by the enemy, but when im on it, the start vector of the raycast is on the enemy and doesnt identify it.
(see the picture)
also, the raycast is going out from the player (forgot to draw it).
this is a 2D game so when im “on” the enemy the raycast dont recognize it.
so what can i do?

bump…

bump

i have edited the explanation, hopefuly its more clear now.
please try to help i really need to fix this.

I appologize I haven’t looked into raycasting for this game yet but I’ll take a stab at it. It looks like this page might be useful to you:

RaycastHit-triangleIndex

If you can manage to create a raycast similar to that example and like the example they provide, give a action for when you hit something, then you can do what you like. Problem is checking if its an enemy or level geometry or something else but that may give you a start at least.

Search for “ray” under documentation for the rest of the things you might need, if you still need help report back with what you’ve found/haven’t found.

thanks for your replay i really appriciate it because ive been looking for a solution for 3 days and dont feel comfortable bumping the thread so much.
the link you gave is a RaycastHit. but the Raycast method will return the RaycastHit only if it hits something, as i said, it never hits a gameObject when the start of the raycast is acctually on the gameObject i want it to hit.