In the current universe, stars form in large molecular clouds, usually having masses thousands of times that of the Sun. Consequently, they usually form in clusters of hundreds or thousands of stars. The discovery of thousands of extra-solar planets in the last couple of decades has demonstrated that many of these stars have planets. So how do these planets form?
The molecular clouds out of which stars form are turbulent, and consequently the blobs that condense to form stars have angular momentum - quite a bit more angular momentum than a star, and more, in fact, than a typical stellar system with planets. One way to deal with the angular momentum is to form a binary or multi-star system, two or more stars orbiting each other, and this is extremely common. Another way is to produce a planetary system, and for our solar system, most of the angular momentum is in the planets - mostly in Jupiter.
When a overdense "core" region of a cloud stars contracting under gravity, the angular momentum means that a significant fraction of the mass will form a disk perpendicular to the angular momentum vector (or, if you prefer, in the plane of the angular momentum bi-vector). This disk is flattened by gravity and viscosity, and its angular momentum resists being sucked into the star.
Our solar system seems kind of neat and simple. The planets close to the Sun are either metallic like Mercury or stony and metallic like Venus, Earth, and Mars, while out beyond the "snow line" where ices could condense, we have the gas giants Jupiter and Saturn and the ice giants Uranus and Neptune. Everything in its place so to speak.
The discovery of exoplanets revealed that the Universe is not that simple. There are hot Jupiters and Neptunes orbiting their stars far closer than Mercury, where they couldn't possibly have formed. Unravelling puzzles like this is one reason planetary formation science is now one of the hottest topics in Astrophysics. It's a good subject for generalists, requiring a mix of dynamics, thermodynamics and radiative transport, geology, chemistry, and stellar physics.