Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Understanding Unity Physics - Double Pendulum

Discussion in 'Physics' started by unity_01F7BF8BFC09359D476A, Nov 23, 2023.

  1. unity_01F7BF8BFC09359D476A

    unity_01F7BF8BFC09359D476A

    Joined:
    Aug 13, 2023
    Posts:
    1
    Currently I am trying to simulate a double pendulum in Unity. The pendulum consists of two cuboid rigid body links. Both links have a mass of 1 kg and are of the same size: a length of 1m, width of 0.1 m and depth of 0.05 m. Each link's rigid body settings are: .useGravity = true, .drag = 0, .angularDrag = 0. Both links contain a hinge joint that is able to rotate around the z-axis and I've set .autoConfigureConnectedAnchor = true. The second link is connected to the first link's rigid body.

    The simulation works and the pendulum swings, but not as expected. I simulated the pendulum I described above in Matlab and this simulation behaves as I'd expect - more "chaotic" than the Unity simulation.

    I've created animations in Matlab that plot the pendulum's trajectory in the x-y-plane. I'll attach both trajectories here.

    Can anyone explain to me why the unity simulation does not behave as a real double pendulum would (or in that case, the Matlab simulation)? Any hints?

    This is the Matlab trajectory:
    matlab.png
    This is the Unity trajectory: unity.png

    Any questions?
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,224
    Unity's physics is about real-time performance. It's not meant to be accurate simulation of real-life physics.
     
  3. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,841
    The accuracy of a physics simulation in any engine is largely determined by its step size (aka timestep). The shorter/smaller the timestep, the higher the accuracy.

    Reduce your fixed timestep in Unity's time settings. See:
    https://docs.unity3d.com/Manual/class-TimeManager.html

    Also, make sure your rigidbodies in Unity have similar damping/drag as in your Matlab simulation. Angular drag in Unity's rigidbodies is non-zero by default (0.05), so your bodies will lose angular velocity over time.
     
    Last edited: Nov 25, 2023