Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stop of rotation
#1
Hello. Please forgive me for my English. I use Google translate.

I would like to smoothly stop the rotation of my soft body. I read the documentation and looked at the examples, but I didn't find a suitable solution. I tried to solve the problem using an array of starting positions of particles. When the button was pressed, I tried to set each particle a speed in the starting direction. Alas. It didn't work out for me. 

My body must constantly fall, hitting other objects. I would like to stop its rotation by pressing a key. Tell me, is it possible? Thank you in advance,
josemendez.
Reply
#2
You know, I kind of did it. I'm not sure if this is working correctly. But it seems to be working. Is it right?

Code:
if (Input.GetKey(KeyCode.Space))
        {
            for (int i = 0; i < actor.solverIndices.Length; ++i)
            {
                int solverIndex = actor.solverIndices[i];
                actor.solver.velocities[solverIndex] = actor.solver.velocities[solverIndex] + (Vector4.MoveTowards(actor.solver.positions[solverIndex], startingRot[i], 100f));
            }
        }
Reply
#3
(30-07-2022, 02:33 PM)mrsloom23 Wrote: You know, I kind of did it. I'm not sure if this is working correctly. But it seems to be working. Is it right?

Code:
if (Input.GetKey(KeyCode.Space))
        {
            for (int i = 0; i < actor.solverIndices.Length; ++i)
            {
                int solverIndex = actor.solverIndices[i];
                actor.solver.velocities[solverIndex] = actor.solver.velocities[solverIndex] + (Vector4.MoveTowards(actor.solver.positions[solverIndex], startingRot[i], 100f));
            }
        }

Hi there!

You're adding a position delta to a velocity, which doesn't make any sense: velocities are expressed in meters per second, while a position delta is just meters. Moreover, assuming startingRot[] contains particle positions at the start, this would not stop only rotation but all particle movement. So in the general case, this won't work.

Unlike rigidbodies, softbodies do not rotate around a single point/axis: each individual part of the softbody may rotate around a different point/axis at a different velocity (this is what makes it soft, if all parts moved in unison around a single point it would be rigid), so first you need to specify what do you mean by "stopping rotation". I assume you mean to stop overall rotation around the center of mass?

If so, you need to calculate the softbody's center of mass, calculate angular velocity around this position, and then apply a torque (rotational force) that opposes this rotation. Obi includes helper functions for 2 of the 3 steps:

Code:
// calculate mass and center of mass:
float mass = softbody.GetMass(out CoM);

// TODO: calculate average angular velocity around CoM, and opposing torque. You can apply the ω = r × v / |r|² formula to every particle, and average the results.

// apply opposing torque, which is just a percentage of the average velocity:
softbody.AddTorque(-avgAngularVel * 0.3f, ForceMode.Acceleration);
Reply