What determines the shape of lightning?
Your assumptions are right.There is indeed physics involved in lightning shapes.
Why can’t lightning just be in a plain, straight shape?
The answer has to do with the complex way a lightning bolt forms. Although it looks like it forms all at once, a lightning bolt is actually produced in many steps. Instead of jumping right to the ground, the cloud’s negative charge begins with a short downward hop.
This initial hop is called a “leader,” and it’s no more than a few hundred feet long. From the lower end of this leader, another leader forms, and from the lower end of this, another. In this manner, the negative charge hops downward from leader to leader like a frog jumping from lily pad to lily pad across a pond.
While this is going on, the ground sends up its own chain of shorter, positively charged leaders. It’s only when these two chains meet, about a hundred feet off the ground, that we see the lightning bolt’s flash.
Lightning is jagged because each leader forms independently of the others. Each place a lightning bolt zigs or zags is where one leader stopped and another one started.
Each place a lightning bolt forks is where two separate leaders formed from the bottom end of a single leader above. This whole process takes only a few thousandths of a second, but that’s enough time to sculpt beautiful and complex lightning bolts.
Fun fact: Lightning is actually 5 times hotter than the Sun's "surface".
Lightning is a form of electric current, so it will find the path of least resistance to the ground, where there is the least amount of negative charge. To get there, the lightning has to travel through part of the atmosphere, but not all air has the same amount of conductivity.
The electric current takes the path of least resistance, or where the conductivity is greatest, so that it can reach the ground with the optimal path. If the entire atmosphere had a uniform conductivity, lightning would be a straight line, perpendicular to the ground. Since regions with high conductivity in the air are random, the lightning appears jagged.
Here's a source going deeper into why that is: https://www.scientificamerican.com/article/why-are-lightning-bolts-j/