10 ms·
PIDs: Creating Stable Control in Games
- bruce343434 3y agoFeels like PIDs are the wrong tool for this problem. Stuff to do with matching animations up to physics is usually better solved with inverse kinematics.
- azeemba 3y agoWhat are you imagining in this situation? How would one use IK with a running animation? You could remove the root motion of the animation and control the position of runner in code. This would allow controlling the position/speed easily but to look natural you still have to tweak the animation speed dynamically. Just changing the foot position via IK would not be enough to make the animation look natural. So feels like you are still left with the original problem of tweaking the animation speed.
- turtledragonfly 3y agoNot the person you asked, but here's a video you might like: https://www.youtube.com/watch?v=LNidsMesxSE&t=268s https://www.youtube.com/watch?v=LNidsMesxSE&t=268s In that example, they do the character's physics first (just a ball), then match the animation to it. The animation speed is controlled by a "surveyor wheel" approach — go to to 336s in the video for that part. So, the animation speed is derived from the physics, rather than the physics speed being derived from the animation. I wouldn't call that "IK" exactly, which would be more for things like matching the foot to individual stair steps as the character walks up them, or such. But I suppose in a broader sense it is, since you're deciding on a physical goal a-priori, then forcing the animation to match that goal.
- azeemba 3y agoThanks for the link! The ideas are presented so well. Really a cool approach too
- oreally 3y agoMy understanding is PIDs are vastly preferred in situations where very often real world measurements have a degree of error in them. Like having the wheels of your car slip extra distance when you put your foot on the paddle for a specific amount of time. It's a feedback system of sorts. If there's no error in measurements, sure, a mix of IK and blending seems to be a lot easier to implement.
- cgg1 3y agoUsing only PD (no I) when tracking also works well. Might be worth adding a short section about that to compare against the full PID.
- azeemba 3y agoInterestingly, there was another PID post earlier today and someone specifically commented on using a PID for camera tracking: https://news.ycombinator.com/item?id=39011630#39016836 https://news.ycombinator.com/item?id=39011630#39016836 I am surprised to hear about a PD controller though. In my testing, a PI controller seemed to behave much better than a PD controller. In my research, it seemed a common strategy to drop the D-component completely but I did not see the suggestion to drop the I-component.
- cgg1 3y agoYMMV I guess :)
- ok_dad 3y agoI used a PD controller for a specific application where we were trying to maintain a specific temperature in the future, and cared more about the trajectory of the temperature over time to reach the goal. We didn’t much care for the integration of that temperature since that wasn’t important in this particular case. An integration factor would actually wind up the rate of temperature change too much!
- dwattttt 3y agoIntegral windup is the term for this issue, there's a few ways to deal with the windup if you need to keep the integral component (e.g. for tracking a moving set point, or to overcome a stable error). https://en.wikipedia.org/wiki/Integral_windup https://en.wikipedia.org/wiki/Integral_windup
- claytonwramsey 3y agoIn terms of the theoretical guarantees, a PD controller is (nearly) always stable and pretty easy to critically damp. However, if the set point is moving with a nonzero velocity or there is some load, then the PD controller will not converge. A PI and a PID controller can converge even if the target is moving. Practically speaking, I would recommend encoding as much model information as possible before pulling out the I term: for instance, if you know the velocity of your tracked object and assume an intertidal model, you can just include some of that data in your feed forward rather than the controller, which simplifies things greatly.
- wombatpm 3y agoPID get real fun when you model physical systems, like say filling a tank while trying to maintain liquid depth and temperature or maintaining a constant reaction rate. You get to start taking laplace transforms. I had a ChemE professor who’d tell stories from the 30’s when chemical engineering was forming as a discipline. Common practice back in the day (before the theory) was to manually adjust parameters until things went unstable, then back off 5%. Turns out the optimum point is the inflection between stable and unstable behavior.
- i_am_a_peasant 3y agoMy whole BSc degree was in systems engineering and automatic control. You make me nostalgic about all those classes that at the time I hated. What a weird feeling.
- zubspace 3y agoThe site explains the three parts of PID's very well. On one hand I like PID controllers. It's a reusable concept which you can apply to a loot of stuff. On the other hand, in my experience it can be very tricky and cumbersome to tweak them. In the given example, a PID makes perfect sense. There's a single, static target location you need to approach. Adjust velocity with a PID and you're done. But what if the target location is not static? Imagine that the character needs to move to your mouse pointer? Do PID's still hold up? How do you handle the I and D term then? It gets even trickier if you move to 3D. You maybe say, hmm, let's use a rigidbody this time instead of a kinematic body for the player character and use PID's to adjust forces to steer velocity and rotation. But I never found a good way to do that, because in those other cases the error depends on the goal you need to reach, and if the goal constantly changes, I and D are kinda useless...
- x86x87 3y agoLol. There is an entire field dedicated to this question. It's called Automatic Control. Yes, you can do all of the above. You need to model it with a multivariable system. Google control systems and systems theory. Usually in a physical control system (that is driven by a PID controller) your limiting factors are the execution element (how fast can you change the input) and your sensors (the resolution of the transducers/sensors dictate the resolution of what you can achieve). A lot of times the PID controller will have a way that it can autotune itself as it's extremely rare to be able to measure the properties of the physical system precisely and for those properties to not vary with temperature and with wear and tear.
- zubspace 3y agoWell, you kind of prove my point, because you made me jump from a 5 minute lecture about PIDs to a study about control systems. Yes, probably there are all kinds of systems to control and autotune a PID. But that's the problem. In gamedev, PID's get constantly recommended for so many things, but when you play around with them you soon realize, that they are quite hard to get right. So then there's two ways: you dive into control systems or you just lerp the value and call it a day.
- ubj 3y agoIf you're learning about PID controllers, do yourself a favor and watch Brian Douglas's video series on the topic: https://youtu.be/wkfEZmsQqiA?si=50WWz4kuber56JIU https://youtu.be/wkfEZmsQqiA?si=50WWz4kuber56JIU Brian has great videos on other control theory topics as well.
- aktau 3y agoThese videos were fantastic, thanks for linking them. The perfect balance of a little theory with practice and examples for someone who has an immediate need to control something but has never taken a control theory class.
- deleted 3y ago[deleted]
- alanir 3y agoThere is a cool sandbox game on steam called “Plasma” that offers a graphical programming environment which includes a basic PID controller. I was really impressed with how easily I was able to make a cube float almost perfectly in 3D space within that game by only using 3 of these controllers (mainly the P and D portions) and some thrusters by monitoring the pitch and roll angles, and how high above the ground the cube was. I was even more impressed when adding some weight to one side of the cube and seeing the system compensate for it automatically. The process of tuning the gains on the different inputs of the controllers, then seeing how the system responded made me think about how this is a similar yet much simpler process to training ML models. I’ve always been a bit skeptical of how easily one would be able to make changes to something as complex as a large ML model, but looking at it like tuning a very complex PID controller kind of made it seem less like black magic to me for some reason
- DoingIsLearning 3y agoFor every PID write up that reviews the theory we need an equally length follow up on the practical aspects of PID tuning and problem modelling.
- pjkundert 3y agoYup, and a good implementation that already handles Integral anti-windup, and damps Derivative bump when changing setpoint, variable cycle rates, etc. Here’s a decent implementation in Python: https://github.com/pjkundert/ownercredit/blob/master/pid.py https://github.com/pjkundert/ownercredit/blob/master/pid.py
- flohofwoe 3y agoThe most bang-for-the-buck feature of PIDs I've seen yet is to smooth out game camera movement so that the camera feels less 'mechanical' (works both for the 3rd-person camera behind a character, or the overhead camera in a strategy game which needs to jump between positions). Just implement the camera positioning and lookat-pointing in the dumbest way possible (including non-continuous, sudden jumps), plug a PID into the position and look-at point, tweak the parameters a bit and voilà, pure magic :)