Amphibious animals adapt their body coordination to compensate for changing substrate properties as they transition between terrestrial and aquatic environments. Using behavioural experiments and mathematical modelling of the amphibious centipede Scolopendra subspinipes mutilans, we reveal an interplay between descending command (brain), local pattern generation, and sensory feedback that controls the leg and body motion during swimming and walking. The elongated and segmented centipede body exhibits a gradual transition in the locomotor patterns as the animal crosses between land and water. Changing environmental conditions elicit a mechano-sensory feedback mechanism, inducing a gait change at the local segment level. The body segments operating downstream of a severed nerve cord (no descending control) can generate walking with mechano-sensory inputs alone while swimming behaviour is not recovered. Integrating the descending control for swimming initiation with the sensory feedback control for walking in a mathematical model successfully generates the adaptive behaviour of centipede locomotion, capturing the possible mechanism for flexible motor control in animals.