I'm trying to implement a spring-mass-dampener system but running into some issues. The linear movement gets into equilibrium as it's supposed to, but the object just keeps rotating until the calculated force is so high it shoots out of sight. At the moment, this is my spring force generator:

            CVector3 displacement = m_Positions[1] - m_Positions[0];
        CScalar distance = displacement.Length();
        // Calculate the spring force based on Hooke's Law
        CVector3 springForce =  displacement * m_Current->GetSpringConstant() * (distance - m_Current->GetRestLength());

        // Calculate the damping force based on damping coefficient
        CVector3 dampingForce =  (m_Velocities[1] - m_Velocities[0]) * m_Current->GetDampeningConstant();

        // Return the total force applied at the attachment point
        m_Current->GetBody1()->AddForceAtPoint(springForce + dampingForce,m_Positions[0]);

And this is the integration:

 if (m_InverseMass < static_cast<CScalar>(0.001)) { return; }
    m_Velocity += m_Force  * m_InverseMass * a_T;
    m_AngularVelocity += m_InverseIntertiaTensorWorld * m_Torque * a_T;

    // Apply damping to linear velocity
    m_Velocity *= (1 - m_LinearDamping);

    // Apply friction to angular velocity
    CVector3 angularFrictionTorque = m_AngularVelocity * m_AngularDamping;
    m_AngularVelocity += (GetTransform().getBasis().GetInverse() * angularFrictionTorque);


I've tried it with several different values but it keeps spinning forever. As far as I know all other functions (including the ones called here) are correct.

  • \$\begingroup\$ Make sure you are using a stable integration scheme. For example symplectic euler ( en.m.wikipedia.org/wiki/Semi-implicit_Euler_method). Standard Euler is known to give exploding solution like you describe. Also can you better describe the system? Is it a spring connecting a point of the body to a fixed point in space? \$\endgroup\$
    – Turms
    Jun 17, 2023 at 10:40
  • \$\begingroup\$ Yes it is a spring connecting the middle of the the "top" side to a fixed point above it. I've implemented the integration used in the cyclone physics engine, which as far as I know is semi-implicit Euler and it seems to have started me on the the right track. The objects seem to move roughly how they should and get into equilibrium but they move very slowly. My guess is it's something with the damping. Anyway, thank you! \$\endgroup\$
    – Dóri
    Jun 17, 2023 at 23:02
  • \$\begingroup\$ When you compute the second correction to angular velocity (given by the friction torque) try to restrict the each component to have opposite sign to the current angular velocity and smaller or equal absolute value. Friction should always decrease velocity. \$\endgroup\$
    – Turms
    Jun 18, 2023 at 15:18


You must log in to answer this question.

Browse other questions tagged .