Detection on Enemies/Actors

I am sure there is a simple solution to this that happens to elude me at the moment.

I co-working on a game and have an issue with non-player characters that navigate the platform based levels. These are controlled directly based on position and several detection areas.
The Enemies are allowed to rotate to a degree as the platforms are not at right angles and involve slopes and non-flat areas.

As an enemy moves (left for example) I use a line of sight check along the travelling side to look for a platform and decide if it should turn around or jump the blockage. This has issues because I have to nip one end of the check within the enemy area to allow the line of sight to work (I understand it will not detect unless it starts within a body). This causes errors in the detection where a detection is not made because of this nipping of the LOS check.

What I 'really' need is a rotated AABB check to grab a block area that covers the height of the enemy and a small detection width.

The picture illustrates the area I need to check (amongst others) based on the rotation of the enemy. As I say, it almost works using LOS. I originally kept the detection to a straight AABB check lifted based on the angle of rotation, but this (though better) also gave issues.

Any help or suggestions would be great.

(Also is a picture of how I was originally doing it with 3 point checks on the areas needed, this worked ok when the check areas where as large as half the distance between, but still not a great solution)
Flash wrote:
What I 'really' need is a rotated AABB check to grab a block area that covers the height of the enemy and a small detection width.


Could you use a sensor on the NPC that is an enlarged version of the NPC's collision?
I could, but I wanted to make sure I could separate areas for L/R sides, ground and head. I need to make sure that a collision against one side is not read as a ground collision, etc.

Perhaps I am missing something fundamental (and believe me, it would certainly not be the first time 🙄 )
How about one smaller sensor for each of the four sides instead of a large one then? Save pointers to the sensor fixtures in your own class linked to the b2Body/b2Fixture or how ever you have it set up. When you get a collision response from a sensor you could turn on/off a flag in your class or what ever.
Erin Catto wrote:
Could you use a sensor on the NPC that is an enlarged version of the NPC's collision?


If I create an outter sensor body to detect where there is a collision setting it as a b2_staticBody and following the main body's position/rotation I don't seem to get a collision reported in PreSolve. Setting it to isSensor=false will have it detect but for obvious reasons I can't do that. Why is a sensor not reported in PreSolve?

EDIT: Nevermind I can see PreSolve() is not called for sensors so I'll be using BeginContact/EndContact instead.

Original thread: https://box2d.org/forum/viewtopic.php?t=4916