Offscreen Enemy Indicators gdevelop?

I’m trying to create an indicator on the HUD showing the direction a specific object is facing, but I’m having trouble. Below is a video example. Has anyone managed to do this or have any tips on how to do it?

Thank you, I await your response.

I would do a distance check between the offscreen enemy and the player. If it’s less than X pixels, enable visibility of the circle icon and another triangle icon behind that rotates to the angle between the player and enemy

I asked Gemini. After it gave me a horrible solution and I had to repeatedly tell it that it was wrong. It suggested using raycast.

Center a basic square object that’s slightly smaller than the camera view. You want it slightly smaller so when it aligns the pointer to the edge that the marker isn’t half on screen and half off screen.

I tested it with a smaller screen object, so I could drag an enemy around it to make sure it was working.

I used a player, enemy, marker and screen object and the scene variables X and Y.

It’s finding the intersection between a line from the player and the enemy and the screen object border.

IDK if a formula instead of a raycast would be any quicker. It uses a simple default collision mask. It would be different is the screen object was round. That would use more process time but a square or rectangular mask shouldn’t use many resources.

I created marker objects at the beginning and linked them to the enemy objects. You could either add the marker as the enemies are created or from inside the for each instance.

My result.

You could stick a text object to the marker and add the distance to the enemy.

I tried here and it didn’t work the way I want. I found an example of how to do it in Construct, but I can’t find it anywhere on GDevelop. I also want the indicator to appear in the HUD. If anyone can give me some guidance on how to do this…

Thank you, I await your response.

I managed to do it here with the help of chatgpt, but now I don’t know how to make the indicator move only on the edges of the screen; I don’t want it to go to the center of the screen. Does anyone know how to do this? Below is a screenshot of the code in gdevelop.