I'm really eager to know how a programmer finds useful a derivative in game development, using a real scenario as an example. Also I plan to use this question to understand the importance of derivatives more!
3 Answers
Derivatives (and integrals) come up everywhere in game physics!
Consider the static force diagram for a ball rolling down a ramp. You need to know the gravity vector, the mass of the ball, and the angle of the ramp (its normal vector); Then you can calculate the net force on the ball and determine the acceleration of the ball in that frame. On the next frame you calculate that all over again for the new conditions and apply acceleration again.
These acceleration value are the derivative of the ball's velocity. To phrase it another way, that acceleration value determined every frame is the rate of change of the velocity of the ball. And the velocity is the rate of change of the ball's position every frame too. To implement these physics you will need to keep track of all 3 vectors every frame and add acceleration to velocity, then add velocity to position. And ta-da, you have a rudimentary physics engine using discrete calculus!
Derivatives can also be used in logical problems like pathfinding, AI, and other kinds of solving for optimal solutions.
An example of this may be generating rivers in a terrain generator. Rivers always flow downhill, so if you randomly select an origin point for a river you will need to calculate what direction is downhill, and usually the steepest downhill direction; This is done with partial derivatives by treating the terrain as a mathematical surface.
I actually did use the derivative once. No, actually it was the integral. But w/e.
Basically I had this inertial scrolling system (in one dimension so a line) and I wanted it so when you stopped scrolling the inertia would move the camera so that it stopped exactly over a selectable option.
The way I did this was you use the normal scroll equations when you're moving your finger. But as soon as you release, it stops using the normal equations and switches to using an integral of the normal equation. From the integral we can easily see the exact spot the camera will stop moving and can modify the equation so that we stop earlier or later.
I will give it to you straight: Unless you are making you own engine, you will almost never use them. Off-the-shelf engines and libraries (which you should be using anyway if you actually want to ship your game before the next decade) usually do a very good job of hiding complex mathematics behind intuitive APIs.
-
\$\begingroup\$ You didn't really answer the question, instead you've told the OP not to worry about it. It's still a valid question with interesting answers. Maybe they are making a game engine. There is no reason to exclude that part of game development from this question. \$\endgroup\$– RomenOct 6, 2021 at 20:41
-
\$\begingroup\$ Game development is one thing and game engine development is another. Mixing them is akin to mixing the role of a tank commander and a tank engineer. \$\endgroup\$ Oct 7, 2021 at 5:01
-
\$\begingroup\$ We have different opinions, many would consider game engine development under the "game development" umbrella. Engine development is still a welcome topic on this stack exchange and also many questions have already been answered where derivatives are used in the answer. I would still consider this answer low quality even if we agreed that the question was off-topic. \$\endgroup\$– RomenOct 7, 2021 at 14:05