Heavy quarks are unique probes to investigate the properties of the Quark-Gluon Plasma (QGP) formed in ultra-relativistic heavy-ion collisions. The ALICE Collaboration measured the D-meson elliptic flow, ν2, in Pb–Pb collisions at sNN=5.02TeV to study the participation of the low and intermediate transverse momentum (pT) charm quarks in the collective expansion of the system. The charm-quark dynamic in the QGP is further investigated through the Event Shape Engineering (ESE) technique. Furthermore, the effect of unprecedented strong magnetic field produced in heavy-ion collisions is studied by measuring the charged-dependent directed flow (ν1) of D0 mesons for the first time at the LHC. Recent results of azimuthal anisotropy of open heavy-flavour decay electrons and muons in p–Pb collisions at sNN=5.02TeV and sNN=8.16TeV, respectively, are also shown.