I think I may be following the wrong approach here...
I have an enemy which uses a RayCast2D to detect a player. The y of the castto does not change. The x only changes depending on the enemy fliph (ie. if he is "looking" left or right).
If an enemy goes up a ramp and the player is at the top of this ramp (so that the RayCast2D approaches the player from below) in one frame the enemy detects the player (and starts attacking, with a change in animation) and in the next, it doesn't (so it stops attacking and goes back to the walk animation) - creating a loop.
There is a small difference in the origin of this Raycast2D leading to the problem above, even so its position is (0,0) on the enemy.
Is there a standard solution to this problem?