In cars, the front wheels follow what’s called “Ackerman Steering Geometry”.
I am trying to find a way to implement this accurately in Unity, and the formula is full of multiplications, divisions and arctan calculations.
Considering that there are two such calculations required for one car, if there are 10 unique cars, in the level all making the same calculations, that’ll cost a lotta performance over time.
The following is an example of the formula. It’s pretty long.
I’ve been thinking of ways to optimize this, and two solutions come to mind:
-
Just directly use the formula to calculate the angle of the steering wheels every frame.
-
This is the most straightforward way to do it, and I fear it might be unnecessarily slow. A bunch of nested calculations, two multiplications, two divisions and an atan calculation.
-
But… could it be fast? From what I can tell, Animation Curves has a bunch of fancy Bezier curve calculations and chances are that evaluating the curve may be slower than just calculating the values directly.
-
During startup, generate an Animation Curve by getting several values from steerInput [-1, 1] and evaluate that Animation Curve to get the angle of the steering wheels.
-
From what I can tell, animation curves are relatively cheap, and if I am able to get a large payoff from doing this, I’d be pretty happy!
-
If this is truly more efficient, I do wonder: What number of keys would be the best balance between accuracy and performance?
-
I also wonder: Should I make one static curve for each car make that every instance of the same make evaluates from, as opposed to a curve generated for every single car? I wonder how much RAM space a curve can occupy.
Of these options, which do you think is the most efficient in terms of performance? Or do you think the performance benefit of the latter is negligible?