-2

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?
  • I have deleted that question because the answer was not clear and did not help me :( – Maqomed Rahmanov Jan 08 '21 at 07:15
  • @Leoverload that link is actually the OP's prior question now deleted ;) –  Jan 08 '21 at 07:29
  • it wasn't before, can I retire a flag ? ;) @MickyD – Leoverload Jan 08 '21 at 07:35
  • 1
    @Leoverload certainly can, just delete the comment above and withdraw close-duplicate vote as necessary :) –  Jan 08 '21 at 08:04
  • 2
    The `Math.Abs` is totally redundant .. and is an absolute distance between a start and current position dependent on the frame-rate? ;) .. Spoiler: It's not – derHugo Jan 08 '21 at 10:45

1 Answers1

1

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);
  • Thank you for your answer but the thing is that I know the originalPosition at the start of the update function and at the end of each update function I am doing newPosition = originaPosition. I am doing it because I don't know the final point of the movement. Is your answer same for this case also? – Maqomed Rahmanov Jan 08 '21 at 07:09
  • @MaqomedRahmanov that's a new question and so you should post it accordlingly but I will say that by `newPosition = originaPosition` then your `distance = 0` anyway so it won't matter in any event. _"I don't know the final point of the movement"_ - well it sounds like you should be taking into account velocity in which case elapsed time becomes important –  Jan 08 '21 at 07:26
  • final point of movement depends on the user who is going to move the object. I don't understand exactly how should I take into account the velocity? – Maqomed Rahmanov Jan 08 '21 at 07:39
  • That sounds like an excellent new question, consider posting it to SO –  Jan 08 '21 at 09:36