Track Distance Traveled Without Using .magnitude or Vector3.Distance()?

I have a missile in my game and I want to keep track of the distance it has traveled to compare against a maximum range.

As it could conceivably travel along a curved path, just comparing its current position against its starting position won’t work for me.

I know I can use .magnitude or Vector3.Distance each time through the Update loop, but I also know that’s a pretty big performance hit.

I’d appreciate any suggestions. Thanks for your time.

It shouldn’t be a huge hit to performance unless you’re doing it a ton in every frame, like if you have thousands of objects doing calculations. Though you can use .sqrMagnitude as it’s slightly better than .magnitude since it’s not doing a square root calculation.

Another option is to track time of flight instead of distance. Especially if it’ll always fly at a constant speed. You can just use flightTime = Time.time - flightStartTime;, or flightTime += Time.deltaTime;.