Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Velocity update skipped every 10th time

Discussion in 'Physics' started by ddi7i4d, Sep 29, 2017.

  1. ddi7i4d

    ddi7i4d

    Joined:
    Sep 21, 2017
    Posts:
    7
    Hello,

    I am dragging an object in VR (Axon 7, Daydream), and to have it a bit lagged behind, I change the velocity every frame to the direction where the target is.
    Problem: On the phone, you see that approximately every 10th time, the object does not move, even though it does have a velocity. On the GIF, you see two of those skips, the number below shows the alleged velocity. I think it doesn’t happen on the PC, but I can’t really tell, because you only notice that in VR with 60fps.


    Vector3 posDelta = targetPoint.position - gameObject.transform.position;
    rigidBody.velocity = posDelta*10;
    GameObject.Find("DebugText").GetComponent<Text>().text = rigidBody.velocity.x.ToString();
     

    Attached Files:

  2. ddi7i4d

    ddi7i4d

    Joined:
    Sep 21, 2017
    Posts:
    7
    I will try to answer my own problem: I think that Unity allows physics updates in the Update() function, but executes only those that would go along with the FixedUpdate() function. So I save the objects last position and last last position, and compare the actual with the last position. If they are the same while velocity is > 0, it didn’t execute the physics update, and I move the object myself for the distance of (actual position - last last position). That smoothes out the mistakes and makes it look quite nice.
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Well I don't actually think it's physics related but you're probably causing Unity to pause regularly as it collects
     
  4. ddi7i4d

    ddi7i4d

    Joined:
    Sep 21, 2017
    Posts:
    7
    Okay thanks, I am learning to understand garbage collection, but does it only pause the object’s physics? Because I can manually change the position, just not by using .velocity
     
  5. ddi7i4d

    ddi7i4d

    Joined:
    Sep 21, 2017
    Posts:
    7
    After a few weeks with Unity, I understand the problem and have a solution: The physics do in fact skip frames (when at 60fps), but that can be avoided with Rigidbody > Interpolation to Interpolate. As this is quite expensive, I only apply that to the object that I am currently holding, and that results in a nice and smooth motion.
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can set the physics simulation to 60fps.

    --Eric