Can someone here help me with a distance check please? thx

Hi, this is for a Beat Em Up style game.

From the NPC’s point of view, off the event tick we first check if Player 00 (P00) or Player 01 (P01) exist. (I am getting direct ref’s to the spawned actors in the game mode).

Now if they both exist, off of Event Begin play there is a set timer that is firing every 3 seconds. This feeds into the distance check MACRO.

The idea here in theory is once every 3 seconds check the distance to each Player and choose the lesser. Then logic can be implemented to move to THAT player.

I don’t know if my math here is off or my nodage, but it does not work, and here the “P01 Closer” print string always triggers no matter how the players move around.
closer

Does anyone know what is wrong here? Any help is greatly appreciated, thanks.

If you follow the logic a little closer (the white lines) you’ll see that it does not match what you describe.

What it does do is check if P00 exists, if so get its distance and then immediately move on to the comparison (again P01Distance which has not been set here and will have whatever value it previously had). If P00 does not exist, then checks if P01 does and sets its distance and then moves on to the comparison (against P00Distance which was not set here…).

You need to move things around so you always to both sets before the comparison, and use the false branches from the existence checks to return something sensible and not compare.