Hi all,
So, I have a somewhat unique situation as far as I’ve determined and I’m throwing this out there to see if anyone has solved it or has any additional recommendations. Warning: this is a slightly long post.
I would like to use a NavMeshAgent in conjunction with a Rigidbody. However, I do not want to use pathfinding–namely, I want to use the NavMeshAgent for its ability to keep my character grounded at all times. Our game does not feature any jumping, nor is the player character able to fall off of edges (this is a somewhat old-school RPG) and the NavMesh did a beautiful job of preventing those two things from happening.
As far as I’ve been able to figure out, navigation updates are done based on the Update function and NOT FixedUpdate. This is important because I would also like for the player character to be able to respond correctly to collisions with static and occasionally moving objects with Rigidbodies. This means, and again, as far as I can tell, I should directly alter the movement of this character within FixedUpdate.
Let me back up slightly: currently, our game handles player input AND movement within the Update function. OK, cool. Camera control is handled in LateUpdate. Still good, everything’s great–until you collide with an object. At this point, an unacceptable amount of jitter enters the fray and it makes sense. I reckon that if you want accurate physics responses, you need to do those updates at the same interval as physics (FixedUpdate)
So like any good programmer, we cheated. We found out early on that changing the Physics timestep to something smaller (IE, smaller period, larger frequency) actually fixed our jittery collision issue. Why? Well, it’s simple in retrospect: when running the game at 60 FPS, the fixed timestep we chose (0.016) matched up closely with the forced update rate of the game (also 60FPS.) This resulted in very smooth collisions. However, this is a terrible thing to do and I would not recommend it as games that do not run at that rate will still suffer from jittery collisions.
So this is a no-go overall, but it solved the problem for certain cases. Eventually, we decided to migrate to a new controller, but problems arise when trying to use a completely physics-based model for determining movement, issues that I don’t necessarily feel like trying to debug, especially when the NavAgent ‘forced groundedness’ already solved these issues. Not to mention our project is quite mature already and redoing our terrain is pretty much a non-option at this point.
So let’s cut to the chase: has anyone successfully used a NavMeshAgent (again, not using it for actual pathfinding) with a Rigidbody? I’ve determined that it does seem possible, at least, in theory to figure out the Navmesh Agent’s ‘sampled position’, which could then theoretically be used in conjunction with FixedUpdate, whether it’s via velocity/MovePosition updates, but I’m wondering how well this works in practice.