19-03-2020, 04:42 PM
(This post was last modified: 20-03-2020, 08:28 AM by MarcPilgaard.)
(19-03-2020, 09:59 AM)josemendez Wrote: Hi,
If you're interested only in the vertical component, you need to:
- Multiply the impulse direction (accesible as cablejoint.Jacobian) by the impulse magnitude.
- Project it onto the gravity vector (a simple dot product).
- Use the magnitude of the projection as your new impulse magnitude.
If you're after the full force regardless of directionality, you need to:
- Project the gravity vector onto the jacobian (again a dot product, since the jacobian has unit length)
- Use the length of the projected gravity vector as your new acceleration.
I have tried implementing the measurement of the full force, I do get some numbers but I am unsure if these are calculated correctly.
The weights I calculate are:
- All weights are negative
- When I move my crane around, slowly, the weight fluctuates alot, much more than I would have expected, sometimes the calculated weights briefly becomes 0.0. But the element we are moving is being moved very slowly, so I doubt it is because the cables starts to slack.
- The summed weight for all four cables are close to the mass of the rigid body they are suspending. Mass of rigidbody 30.000 ~ Total weight across four cables 30.800.
Current implementation:
Code:
private void FixedUpdate()
{
//Last joint where the weight is attached
CableJoint joint = cable.Joints[cable.JointCount - 1];
//The gravitional acceleration vector
Vector3 grav = new Vector3(0, -9.82f, 0);
//Projecting the gravitational vector onto the Jacobian vector
float dot = Vector3.Dot(grav, joint.Jacobian);
//The projected gravity vector
Vector3 gravProj = joint.Jacobian * dot;
// Calculate force by diving Impulse with Time
float force = joint.ImpulseMagnitude / Time.fixedDeltaTime;
//Calculate the weight by dividing the force with the magnitude of the projected gravity vector
weight = ((force / gravProj.magnitude));
}