Coding Tip: Using Desmos to Find CurvesAugust 12, 2016 I recently started using Desmos, a free graphing tool, to come up with curve equations for my C# scripts. Occasionally it can be helpful to have the formula for a specific curve in order to have more control over the modulation or falloff of a value. For instance, I recently had to code a waypoint system for VR that has the player look at specific waypoints around them; depending on the distance of their gaze from the waypoint, it will scale up the waypoint size slightly to give them visual feedback. The problem I was running into was that when the player was too close to the waypoint, this scaling range felt way too large, so depending on the distance to the waypoint, the gaze activation distance should change as well. In short, I needed to find a curve that would modulate the gazeActivationDistance in an ideal way. From there I was able to decide what the gazeActivationDistance should be at various distances from the waypoint, and using that I could plot a curve that generally fit what I wanted. I knew at a distance of 1m from the waypoint the gazeActivationDistance should be 1.2m, and at a distance of 2m from the waypoint it should be 1.3m, and at a distance of 3m it should be 2.2m. Using desmos.com and Epic Pen (a great little tool!), I was able to first mark down the points I knew, and then formulate an equation through trial and error. Because I’m not a calculus expert, I find this workflow fairly effective in getting me the results I need. Starting with the basics — exponents make curved parabolas, dividing extends the length of the curve, and adding offsets it in the y axis, I was able to plug in the values I needed as you can see in the video below: And finally, here is the equation in C#:


© 2019 Borrowed Light Studios LLC 
Leave a Reply