/// <summary> /// Advances the simulation a given amount of time. Note that once BeginStep has been called, /// Substep can be called multiple times. /// </summary> /// <param name="stepDeltaTime"> Duration (in seconds) of the substep.</param> protected void Substep(float substepDeltaTime) { using (m_SubstepPerfMarker.Auto()) { // Necessary when using multiple substeps: ObiColliderBase.UpdateColliders(); // Grab rigidbody info: ObiRigidbodyBase.UpdateAllRigidbodies(); IntPtr stepSimulation = Oni.CreateEmpty(); // Generate a task for each solver's step, and combine them all together: foreach (ObiSolver solver in solvers) { if (solver != null) { Oni.AddChild(stepSimulation, solver.Substep(substepDeltaTime)); } } // Schedule the task for execution: Oni.Schedule(stepSimulation); // Wait the task to complete: Oni.Complete(stepSimulation); // Update rigidbody velocities: ObiRigidbodyBase.UpdateAllVelocities(); } }
protected void CreateRigidbody() { obiRigidbody = null; // find the first rigidbody up our hierarchy: Rigidbody rb = GetComponentInParent <Rigidbody>(); Rigidbody2D rb2D = GetComponentInParent <Rigidbody2D>(); // if we have an rigidbody above us, see if it has a ObiRigidbody component and add one if it doesn't: if (rb != null) { obiRigidbody = rb.GetComponent <ObiRigidbody>(); if (obiRigidbody == null) { obiRigidbody = rb.gameObject.AddComponent <ObiRigidbody>(); } } else if (rb2D != null) { obiRigidbody = rb2D.GetComponent <ObiRigidbody2D>(); if (obiRigidbody == null) { obiRigidbody = rb2D.gameObject.AddComponent <ObiRigidbody2D>(); } } }