01-08-2022, 07:48 AM
(This post was last modified: 01-08-2022, 08:40 AM by josemendez.)
(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);