reeseschultz / ReeseUnityDemos

Unity packages and demos—emphasizing ECS, jobs and the Burst compiler—by Reese and others.
https://reese.codes
MIT License
516 stars 45 forks source link

If a path traversal is currently in progress when a new path is calculated, part of the new path is skipped #39

Closed Tricnic closed 4 years ago

Tricnic commented 4 years ago

Bug description:

When a NavAgent is traversing a path and NavNeedsDestination is added, causing the path to be recalculated, NavAgents will skip part of the new path, possibly passing through obstacles and/or going off the NavMesh.

Steps to reproduce the behavior:

  1. Open ReeseUnityDemos project
  2. Open the NavPointAndClickDemo scene
  3. Create a cube under Surface 1 and give it a position of (2.45, 3, -0.75) and a scale of (1, 6, 8.5)
  4. Bake Surface 1's NavSurface
  5. (For ease of testing) Disable NavRotator script on Rotating Basis GameObject
  6. Click Play
  7. Click in Surface 1's lower right corner, to the right of the new cube
  8. When the dinosaur is close to, but has not reached the destination, click in the middle of Surface 1
  9. Watch as the dinosaur passes through the cube and heads straight for the new destination

Expected behavior:

The NavAgent should follow a new path around the cube.

Describe alternatives or workarounds you've considered:

I was able to get the NavAgent to follow the new path by adding agent.PathBufferIndex = 0; on line 135 of NavPlanSystem.cs after pathBuffer.Clear(); I don't believe there are any far reaching ramifications to this change, but I could be wrong.

reeseschultz commented 4 years ago

Good catch! The code change you're suggesting corrects an oversight for sure, but it impacts the NavMovingJumpDemo, resulting in falling agents who jump from a particular angle. My impression is that this is related to #21, so I need to tackle both issues. "Sticking a jump" is kind of a hack where I've been forcing re-planning, but obviously that's not a rigorous solution. I'll dig into this and see what I can do.

reeseschultz commented 4 years ago

Said problem was not related to #21, but instead related to this vestigial line of code in the NavInterpolationSystem:

localWaypoint.y = agent.Offset.y;

@williamtsoi ran into issues with that line of code as well in #37, so I'm just going to remove it from the main branch now.

reeseschultz commented 4 years ago

Patched in nav/v0.10.4. Thanks @Tricnic for finding this issue.