Improvising in dance classes with other musicians can be wonderful! Here are a few things I’ve learned to make cool and effective:
Play more simply than you would as a soloist, and leave lots of space.
Play quieter than you would as a soloist, especially if you’re a drummer/percussionist.
Inject new ideas/motifs/gestures from time to time - don’t just imitate what you hear.
Limit the number of pitched instruments. It can be difficult to coordinate harmonic progressions between a pianist, bass player, and guitarist. Take turns or play some pitched instruments to let the pitched instruments have some freedom to explore and modulate.
Create a system to coordinate if you have more than one pitched instrument. For instance, decide on a harmonic progression, mode, or main rhythmic motif(s) for each combination.
Watch the dance. It’s tempting to get lost in the music when you’re part of an ensemble, but it’s more important to watch what’s happening on the dance floor!
Listen to the dance teacher. Keep an eye and ear on the teacher during while playing. Also, it’s easy to get chatty with the other musicians between combinations (finally we’re not alone!), but best to keep focused. Do what’s needed to coordinate, just keep the “idle chit-chat” to a minimum!
Decide (or know based on context) who the ensemble leader is, and follow their lead. Collaborations tend to work best if there is a “benevolent dictator” who can make decisions.