Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Multiple rope: Different simulation problem
#6
(29-03-2022, 10:34 AM)schromercy Wrote: Sure, i've sent the project using same title of this thread Sonrisa 
Hope that helps

Hi!

Took a look at your project, the issue is that you're mixing up velocities and forces.

You change the rigidbody velocity in FixedUpdate() ignoring its mass. Since the solver is also updated in FixedUpdate() but it does take masses into account, the order in which Unity calls FixedUpdate for each object (which as you know is undefined by default) will affect the result. There's two possibilities:

A) if the handle's FixedUpdate is called first, it will change the rigidbody velocity. Then Obi will perform its simulation using this (very large) velocity value, but is able to correct it using the forces applied by the rope. This is what you labeled the "correct" behavior.

B) if the handle's FixedUpdate is called last, Obi will perform the simulation first. Then your handle will set a new (very large) velocity value, that Obi has no chance to correct until the next frame. This is what you labeled "wrong".

Possible solutions:

- Modify your handle script to actually use forces (right now you're using velocity deltas). This:
Code:
_rigidbody.AddForce(desiredForce, ForceMode.VelocityChange);

must be this:

Code:
_rigidbody.AddForce(desiredForce, ForceMode.Force);

This way both Obi and your script use forces and everything will work correctly regardless of update order. It is also the physically correct way to do it, since you want heavier objects to be harder to drag.

Also, I'm not quite sure why you subtract the current's rigidbody velocity from your velocity delta. This will introduce further order dependency, since the velocity at that point might or might not have been altered by Obi yet. If all you want is to drag the object using a force, these two lines are not needed:

Code:
desiredForce -= _rigidbody.velocity;
desiredForce = desiredForce.NewZ(0);

- Explicitly set the order in which you want things to happen, by changing script execution order. Set your TestHandle script to run before all other scripts in the game (including Obi). This will ensure Obi runs after your handle script has modified the velocity, and it can apply a correct force value.
Reply


Messages In This Thread
RE: Multiple rope: Different simulation problem - by josemendez - 29-03-2022, 11:17 AM