Understanding Unity Physics - Double Pendulum

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:
9488341--1335310--matlab.png
This is the Unity trajectory:9488341--1335313--unity.png

Any questions?

Unity’s physics is about real-time performance. It’s not meant to be accurate simulation of real-life physics.

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:

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.