Lagrangian mechanics is nice for a few different reasons:
- You can add constraints directly into the differential equation which leads to the equations of motion of a body.
- You can use whatever coordinate system best suits your purpose, so long as you can represent an object's potential and kinetic energy in terms of those coordinates.
- It's not too hard to take into account many particles interacting at once, even though it can be computationally expensive - which would be a problem no matter what method you try to use to analyze the system.
Let's look at some cases where these could be useful.
- As I know you're aware, constraints are easy to add in to the Euler-Lagrange equations, i.e. the equations of motion from a Lagrangian. You simply add in another term, a sum of all the constraints. It's essentially an application of Lagrange multipliers, if you've used those before. In a game, this can be useful if you want a players to move on a certain surface or path (at least one Game Development question has asked for something like this, Specific path for ai for follow). Here, Newtonian mechanics is very close to useless. Go for the Lagrangian approach.
- Say you have a character swinging on a pendulum. If you've done some basic mechanics, you probably know how to approach the system in terms of Newtonian kinematics. This is often simple. But what if you have multiple pendula? The equations of motion for, say, a double pendulum are nasty, but they can be computed numerically . . . if you can come up with the suitable Lagrangian. Doing a Newtonian analysis in terms of forces would be much, much harder.
- Swinging on ropes can also be modeled using Lagrangian mechanics. For instance, you could approximate a rope of length \$l\$ as a bunch of \$N\$ tiny pendula with lengths \$l/N\$. In the limit as \$N\$ goes to infinity, you have a very good simulation of a rope of constant length. Do you want Mario to swing from one tree to the next on a vine? This kind of thing can work well. You could also use a Lagrangian density if you want to study the rope as a continuous object, without breaking it into discrete pendula. Rope physics as a whole can actually be described using a Lagrangian. It is the simplest way to approach the general catenary problem (see also a case using the Lagrangian density). Static or moving ropes can both be studied this way.
- Do you want to navigate an field of really massive asteroids, in a spaceship? Well, if the asteroids are going to influence the ship via gravity (in real life, they won't), you have some options. Here, you could use the Newtonian approach of forces, but that can be a little annoying. Alternatively, you could create a Lagrangian and figure out the potential energy at any point, then simply find the equations of motion. If you assume the asteroids are somehow fixed (again, not realistic), then this becomes less tricky.
- Actually, you can extend the previous example using any type of potential. Do you want your potential energy to be proportional to the distance between two objects raised to the 14th power? What about something more complicated, like \$14e^xx^2\sin x\$? Or what if the potential is somehow tied to the target object's velocity? All of this can be taken into account in your Lagrangian, and the Euler-Lagrange equations can be derived without too much trouble. Solving them numerically would be a pain, but so would doing it any other way.
Basically, Lagrangian mechanics isn't just useful in terms of constraints. It makes finding the equations of motion much easier, in any coordinate system you want, for any potential you want. Sometimes, that can be really helpful - and much better than having to constantly split forces up into different vectors.
You also may want to look into Hamiltonian mechanics. The Hamiltonian, \$H\$, is the Legendre transform of the Lagrangian, \$L\$, and results in a pair of coupled differential equations. I think most people would prefer to use Lagrangian mechanics; if you really want to, you can use Hamiltonian mechanics, but some applications may be trickier.