Yesterday, 01:40 PM
(Yesterday, 12:06 PM)josemendez Wrote: I still think I don't understand your use case at all... if you just want to make the rod follow input "depth" (whatever that may mean in your game) while following physics, calculating and adding an acceleration is the proper way to do it.
You are right, maybe my last example was just bad.
Consider rod controlled by some input number - starts with 0, then over time goes to 5. Every update rod velocity is upated to: inputDelta / dt.
After traveling 3 meters rod hits the wall, in result force is applied, but wall stops it from moving. In the end desired input was 5, while rod stopped at 3.
Then I pulled rod back to 0 (via input) and in result rod will end up in -2. This is the second setup I had (first one was just simple rigidbody attachment) and to fix that problem I still tried to move one particle to desired position - it worked similary to static attachment, but that obviously forces rod into unstable state.
But I noticed this approach is simply wrong and I need different solution.
(Yesterday, 12:06 PM)josemendez Wrote: If you literally mean force = movement delta, it doesn't make any sense: F = ma, so the resulting acceleration depends on mass. Depending on the mass of your rod, using movement delta as a force could result in an absurdly high (or low) acceleration.Overriding velocity ignores mass of particle, and when I used external forces I divided force by mass inversed to account that. The problem with controling velocity was that I use huge solver damping and result is affected by that.
What you want is to use movement delta to calculate acceleration regardless of mass - that is, a spring.
Using a damped spring will typically give better results as it avoids overshooting, and it's not much more complicated to implement: just subtract current velocity times some "damping" parameter: F = -kx-vd, or F = stiffness * (current pos - desired pos) - velocity * damping.
In any case I talked about previous setup, and it was not spring, but plain (velocity+= or velocity=).