Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Rope position delay from parent
#1
[Image: 979klqD.gif]

If i change the simulation order off of Fixed Update it will snap properly but need it to interact with other physic objects properly.

Any advice?
Reply
#2
Hey what software did u use to record the video? When I try using OBS studio the cloth plugin starts bugging out (cloth behaives like a bunch of spiky triangles).
Reply
#3
(15-05-2018, 08:02 PM)cubrman Wrote: Hey what software did u use to record the video? When I try using OBS studio the cloth plugin starts bugging out (cloth behaives like a bunch of spiky triangles).

Licecap. It captures gifs.
Reply
#4
(15-05-2018, 07:57 PM)VirtualCucumber Wrote: [Image: 979klqD.gif]

If i change the simulation order off of Fixed Update it will snap properly but need it to interact with other physic objects properly.

Any advice?

Use "After Fixed Update" as your simulation order, if the object is moved using animation.

If you're not using animation but procedural movement in Update(), do it in FixedUpdate() instead.
Reply
#5
(16-05-2018, 12:02 PM)josemendez Wrote: Use "After Fixed Update" as your simulation order, if the object is moved using animation.

If you're not using animation but procedural movement in Update(), do it in FixedUpdate() instead.

My movement is in FixedUpdate() 

Code:
public void FixedUpdate()
   {
       Move();
   }

private void Move()
   {
       targetVelocity = canMove ? input * moveSpeed : Vector2.zero;
       float targetXAccelerationTime = input.x == 0 ? decelerationTime : accelerationTime;
       float targetYAccelerationTime = input.y == 0 ? decelerationTime : accelerationTime;
       velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocity.x, ref velocityXSmoothing, targetXAccelerationTime);
       velocity.y = Mathf.SmoothDamp(velocity.y, targetVelocity.y, ref velocityYSmoothing, targetYAccelerationTime);

       rb.velocity = velocity;
       transform.rotation = Quaternion.Euler(0, 0, velocity.x * torque);
   }

This is my movement, simply using Rigidbody velocity.

EDIT:
I could easily Translate the object instead, just wanted to keep it simple with a small project.
Reply
#6
(16-05-2018, 01:59 PM)VirtualCucumber Wrote: My movement is in FixedUpdate() 

Code:
public void FixedUpdate()
   {
       Move();
   }

private void Move()
   {
       targetVelocity = canMove ? input * moveSpeed : Vector2.zero;
       float targetXAccelerationTime = input.x == 0 ? decelerationTime : accelerationTime;
       float targetYAccelerationTime = input.y == 0 ? decelerationTime : accelerationTime;
       velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocity.x, ref velocityXSmoothing, targetXAccelerationTime);
       velocity.y = Mathf.SmoothDamp(velocity.y, targetVelocity.y, ref velocityYSmoothing, targetYAccelerationTime);

       rb.velocity = velocity;
       transform.rotation = Quaternion.Euler(0, 0, velocity.x * torque);
   }

This is my movement, simply using Rigidbody velocity.

EDIT:
I could easily Translate the object instead,  just wanted to keep it simple with a small project.

In Unity, the order of events is the following:

- FixedUpdate (0, 1, or more times)
- Animation update
- WaitForFixedUpdate (After Fixed Update in Obi)
- Update (just once)

So if you are moving the object in Fixed Update(), setting the solver update order to "After Late Update" should ensure simulation happens after the object has been translated.

Edit: Also, ObiSolver exposes lots of C# events that are called at particular times during the simulation loop. OnStepBegin, OnStepEnd, OnBeforePositionInterpolation,OnFixedParticlesUpdated... etc. You could insert your code in a delegate to be called during OnStepBegin, which is triggered every FixedUpdate just before starting the simulation step. This way you could still use Fixed Update simulation order.
Reply
#7
(16-05-2018, 02:11 PM)josemendez Wrote: In Unity, the order of events is the following:

- FixedUpdate (0, 1, or more times)
- Animation update
- WaitForFixedUpdate (After Fixed Update in Obi)
- Update (just once)

So if you are moving the object in Fixed Update(), setting the solver update order to "After Late Update" should ensure simulation happens after the object has been translated.

Edit: Also, ObiSolver exposes lots of C# events that are called at particular times during the simulation loop. OnStepBegin, OnStepEnd, OnBeforePositionInterpolation,OnFixedParticlesUpdated... etc. You could insert your code in a delegate to be called during OnStepBegin, which is triggered every FixedUpdate just before starting the simulation step. This way you could still use Fixed Update simulation order.

I had it simulate after fixed update at first but when i started pinning physics objects to it, the objects would not react.
[Image: 1uEV6j1.gif]


And I would assign that function to the event like this?
Code:
private void Start()
   {
       solver.OnStepBegin += Move;
   }
Reply
#8
(16-05-2018, 04:05 PM)VirtualCucumber Wrote: I had it simulate after fixed update at first but when i started pinning physics objects to it, the objects would not react.
[Image: 1uEV6j1.gif]

Yes, as the rope is being simulated after regular physics, so rigidbodies will ignore the rope. You should use OnStepBegin then, to make sure the order in which things happen each FixedUpdate() is this:

- The object moves (your Move() function is called)
- The rope is simulated.
- Rigidbodies are simulated.

(16-05-2018, 04:05 PM)VirtualCucumber Wrote: And I would assign that function to the event like this?
Code:
private void Start()
   {
       solver.OnStepBegin += Move;
   }

Yes, but make sure the function parameters match the delegate parameters.
Reply
#9
(16-05-2018, 04:32 PM)josemendez Wrote: Yes, as the rope is being simulated after regular physics, so rigidbodies will ignore the rope. You should use OnStepBegin then, to make sure the order in which things happen each FixedUpdate() is this:

- The object moves (your Move() function is called)
- The rope is simulated.
- Rigidbodies are simulated.


Yes, but make sure the function parameters match the delegate parameters.

Thanks for the info.
Sorry for spamming with questions but i havent dealt yet with Delegates and Events. I get the jist of them just havent used them.

I cant just have:
Code:
private void Start()
   {
       solver.OnStepBegin += Move;  
   }

public void Move(object sender, EventArgs e)

Do i have to declare a delegate in the ObiSolver class and assign its type to OnFrameBegin/End ?
Reply
#10
(16-05-2018, 05:06 PM)VirtualCucumber Wrote: Thanks for the info.
Sorry for spamming with questions but i havent dealt yet with Delegates and Events. I get the jist of them just havent used them.

I cant just have:
Code:
private void Start()
   {
       solver.OnStepBegin += Move;  
   }

public void Move(object sender, EventArgs e)

Do i have to declare a delegate in the ObiSolver class and assign its type to OnFrameBegin/End ?

Yes, you can just have that. I meant that the arguments of your Move() function should be the same ones declared for OnStepBegin, but I see you already did that.
Reply