Search code examples
c#unity-game-engineframe-rategoogle-cardboard

Should the frame-rate dependency taken into account in the calculation of Vector3.Distance?


I have a thesis project where I am moving different game objects with cardboard. The interaction with game objects is done with the cross-hair. Currently, I am grabbing the object and trying to calculate the distance that the object traveled. In other words, I am grabbing the object and move it with cross-hair. Currently, I am calculating the distance like this :

distance = (Math.Abs (Vector3.Distance (newPosition, originalPosition)));

My question is as follows:

  • Should I take into account the framerate dependency and multiply the distance to Time.deltaTime or this distance is framerate independent?

Solution

  • Should I take into account the framerate dependency and multiply the distance to Time.deltaTime or this distance is framerate independent?

    No because:

    1. you already know the original and new positions
    2. distance calculations doesn't involve time even during instantaneous calculations

    Frame rate or more importantly time since last update impacts when you are calculating a new position based on velocity. In this case time since last update is used as a scalar.

    By the way the line

    distance = (Math.Abs (Vector3.Distance (newPosition, originalPosition)));
    

    ...can be simplified to:

    distance = Vector3.Distance (newPosition, originalPosition);