Open iamallama opened 3 years ago
I confirm it is happening too in ummorpg 2d remastered.
physics2d raycast might be the solution here
hm. the tree is technically an obstacle. will have to think about that one for a bit
the navmesh raycast technique in CanAttack is from ummorpg3d. I think that was important. will have to experiment a little
Versions (please complete the following information)
Describe the bug Monsters won't attack a player when they come to a stop around a corner of the navmesh. If you get a monster to aggro and follow you, and you walk around a corner (based on navmesh), but stop near the edge of that corner. The monster will walk up to within attack distance for their skill (direct line of sight), but the call to
Entity.CanAttack
will return false because of a call toNavMesh2D.Raycast
that hits the corner and so thinks there is an obstacle in the way. This can sometimes be true that there is an obstacle in the way, but with the navmesh agent radius buffers that get built into the navmesh, it's often unlikely to be the case. See the image below:What you see here is the scene view. You can see the blue outlines of the navmesh wireframe. And the player moves around a corner of the navmesh (with apparently clean line of sight due to buffers). The monster moves up to their stop position for the attack and stops within the range of their attack distance, but won't attack due to the raycast in
Entity.CanAttack
going off mesh. The red lines that show up are a debugging that I added that callsDebug.DrawLine
between the monster and player when the raycast goes off mesh. This shows for 5 seconds each line and fires once per frame.To Reproduce Steps to reproduce the behavior, please explain every single click that is needed:
idle
state.Expected behavior Monster should attack when in proximity and no obvious obstacle in it's line of sight to player.
Screenshots/Video See above.
System (please complete the following information):
Additional context Removing the raycast check in
Entity.CanAttack
allows attack to continue, but at the cost of allowing attacks through walls, etc. Since the raycast works using the navmesh which would include any agent radius buffers. Places with narrow paths would basically be near impossible to attack through because the narrow paths give very small sight lines. Perhaps the navmesh raycast should be replaced with a physics2d raycast which should help remove the agent radius buffer issue. Or some other method to determine stopping position that takes the navmesh into account would be needed, though harder.This could maybe be done by calculating a path to the entities position and checking the last leg of the path generated. If greater than the attack distance, then just moving within proximity should be fine. If less than attack distance, move to the start of that last leg which should be within attack distance and also most likely the closest position with a "clear shot" on the navmesh to the target.