4 ms·
I believe this is actually an example of what's known as a "proportional derivative controller", which is effectively an underdamped spring. With a PD controll
by jesse__ 4y ago
I believe this is actually an example of what's known as a "proportional derivative controller", which is effectively an underdamped spring. With a PD controller, the further the target points are apart, the faster the interpolation.
Lerp, on the other hand, is linear; the interpolation speed should not change:
Lerp(int A, int B, float t)
{ return (1.f-t)A + (tB); }
In the example implementation I present, it's assumed that t is pre-modulated by the framerate delta time, and within the bounds (0.f, 1.f)
You can easily make a PD controller out of a lerp, but (without a lot of gymnastics) you can't create a lerp out of a PDC.. at least as far as I know.
- bduffany 4y agoIt's also an example of a PID controller with the integral and derivative terms set to zero: https://en.m.wikipedia.org/wiki/PID_controller https://en.m.wikipedia.org/wiki/PID_controller
- hi_hello 4y agoIn PID terms, this is even simpler yet - just a proportional controller. Only the error between the target and current position are acted upon by a single (proportional) gain: (targetPosition.x - position.x)0.2 == ekP A derivative term would be applied to the difference between the previous and current error, usually in order temper the rate of change. D terms can be a proper headache in practice, especially if you have any noise in your system...
- dahart 4y agoIt’s funny, a while back I was working on a video game and starting writing a dumb AI driver for a semi-physical car. I started by doing the thing in the article, using the P term only, for the steering input to the car. It’s the same thing I’d done for follow-cameras in games with success. Much to my surprise, steering a car in proportion to how far off track it is turns into an oscillation, and the more you damp the proportional term, the more unstable and divergent the oscillation gets! Well I’d had differential equations in college, but when someone told me that me PID controllers were the solution to my driving AI, I was very surprised I’d never heard of them before. PID controllers are neat, they’re almost like a suspension shock with an adjustable spring that has damping and rebound controls, but unitless and you can plug them into anything.
- SomeCallMeTim 4y agoThat is lerp. Yes yes yes. Ugh. I've written that exact function in multiple languages for probably a dozen projects or more.