Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rope ends didn't move correctly
#6
(20-05-2020, 01:21 PM)Kifwat Wrote: Ok I see, but as you know there's no way to move the NavMesh in FixedUpdate, is there any way we can fix this?

Why not? by default its automatically updated in Update(), but nothing stops you from doing it manually anywhere else. Simply turn updatePosition off, then update the transform position yourself. Same for rotation if desired. There's even an example of this in the documentation:
https://docs.unity3d.com/ScriptReference...ition.html

This script works fine for me: it subscribes to the solver's OnBeginStep event (that happens right before each physics step, regardless of where it is taken) and updates the agent there:

Code:
using UnityEngine;
using UnityEngine.AI;
using Obi;

public class NavMeshAgentUpdater : MonoBehaviour
{
   public Transform goal;
   public ObiSolver solver;

   private NavMeshAgent agent;

   private void OnEnable()
   {
       agent = GetComponent<NavMeshAgent>();
       agent.updatePosition = false;
       solver.OnBeginStep += Solver_OnBeginStep;
   }

   private void OnDisable()
   {
       solver.OnBeginStep -= Solver_OnBeginStep;
   }

   // Update is called once per frame
   void Update()
   {
       if (Input.GetKeyDown(KeyCode.Space) && goal != null)
       {
           agent.destination = goal.position;
       }
   }

   private void Solver_OnBeginStep(ObiSolver solver, float stepTime)
   {
       transform.position = agent.nextPosition;
   }
}

Alternatively, you could just update the solver after the agent, by writing your own updater component or using the included LateUpdater component. However keep in mind that using a variable fixed timestep is not ideal. For accuracy using a fixed timestep should be preferred. See:
http://obi.virtualmethodstudio.com/tutor...aters.html
Reply


Messages In This Thread
Rope ends didn't move correctly - by Kifwat - 19-05-2020, 10:13 PM
RE: Rope ends didn't move correctly - by Kifwat - 20-05-2020, 12:11 PM
RE: Rope ends didn't move correctly - by Kifwat - 20-05-2020, 01:21 PM
RE: Rope ends didn't move correctly - by josemendez - 20-05-2020, 02:45 PM