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

Moving a physics object smoothly

Discussion in 'Physics for ECS' started by dispatch_starlost, Sep 6, 2019.

  1. dispatch_starlost

    dispatch_starlost

    Joined:
    Nov 17, 2017
    Posts:
    37
    Hello everyone,

    I'm in early stages of dev on a new project, and am currently stuck on moving the player object smoothly. I have a feeling something in my setup isn't right. I'm on 2019.3 beta, using Physics 0.2.0, Entities 0.1.1, Burst 1.1.2.

    My hacked together setup is:

    - Player entity with physics shape and body + gameplay components
    - Player-follow GO entity, used for MBs such as effects on the player
    - Camera follows the GO entity with some lerping

    - System to move GO entity to linked entity (which is the player entity)
    - System to move player entity based on input values

    When moving the player via adjusting the Translate and Rotation components, it's smooth as butter, however I believe this isn't the correct way as it would require manually doing physics on the player each frame to ensure it doesn't go through colliders, yeah?

    When moving the player via the PhysicsVelocity ApplyLinearImpulse function, the smoothness is tied to the framerate, though even at a capped 60fps it jitters a little occasionally. On test device which fluctuates 40-50fps it looks terrible. I've tried moving the physics systems to fixedupdate, this made the player constantly stutter. I feel like fixed update + interpolation between frames could work.

    I think my overall implementation isn't correct. Feels like the physics is missing interpolation between frames.

    Can someone please provide some guidance? This has been driving me crazy for a few weeks now. What is the correct way to move a physics body smoothly?
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Unity physics have a physics and rendering world, so you perform your physics in the physical world, but render interpolated in the other world.
     
  3. dispatch_starlost

    dispatch_starlost

    Joined:
    Nov 17, 2017
    Posts:
    37
    Hi hippocoder

    Is there an example on the repo I can dive into? I have no clue how to render interpolated... for reference the entity has rendermesh on it. Am I missing some setting somewhere or do I need a new system?

    Edit. If it matters, using the UniversalRP
     
  4. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
    I am interested in how to do this as well
     
  5. dispatch_starlost

    dispatch_starlost

    Joined:
    Nov 17, 2017
    Posts:
    37
    I put this on the backburner and went onto other things. I figure once Physics and ECS are more mature there will be more info.

    When I have things working nicely I will update this thread... in the meantime if anyone has a checklist sort of thing for moving something with the new systems using physics, please post it
     
  6. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
    I posted a question in the physics thread as well. We'll see if an answer will be provided. If I remember correctly there were some mention that for the moment the system is fps depended but will be made independent in future releases.
     
  7. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65