Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

physics ApplyImpulse in editor vs release

Discussion in 'DOTS Physics' started by Marijn_Kiwi, Aug 14, 2019.

  1. Marijn_Kiwi

    Marijn_Kiwi

    Joined:
    May 15, 2013
    Posts:
    9
    I have a projectile on which i apply an impulse
    Code (CSharp):
    1.  
    2. struct ApplyImpulseJob : IJobForEachWithEntity<ApplyImpulse, PhysicsVelocity, PhysicsMass>
    3. {
    4.   public EntityCommandBuffer.Concurrent Cmd;
    5.   public void Execute(Entity entity, int idx, [ReadOnly] ref ApplyImpulse impulse, ref PhysicsVelocity velocity [ReadOnly] ref PhysicsMass mass)
    6.  {
    7.     velocity.ApplyLinearImpulse(mass, impulse.Impulse);
    8.     Cmd.RemoveComponent<ApplyImpulse>(idx, entity);
    9.   }
    10. }
    11.  
    In the editor the amount for the impulse seems fine, but when i build & run, the projectiles seems to be traveling alot faster. I had the same problem with my movement-system, which i ended up changing to manual update from FixedUpdate() inspired by this thread

    However, this does not help with my impulse-system. How can i get the impulse-amount to match results in both editor as release?
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    2,403
    I suspect your issue relates to physics at the moment is frame dependent (as it's not currently running in fixed update where it should be.)

    velocity = 10 will net different results at different fps
     
  3. Marijn_Kiwi

    Marijn_Kiwi

    Joined:
    May 15, 2013
    Posts:
    9
    I'm aware of that, but how can i move an 'ApplyImpule' to a PhysicsVelocity to a fixedupdate? I would expect that the physicssystem would do that for me? Or is that a limitation of the physicssystem at the moment?
     
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,034
    It was in fixed update, but was moved to update loop cause of bug, after fixing that, SimulationSystemGroup (where physics works) will be moved in to fixed update player loop, until that - yes it’s limitation
     
  5. Marijn_Kiwi

    Marijn_Kiwi

    Joined:
    May 15, 2013
    Posts:
    9
    Allright, thanks for the help! Guess I'll stop putting time in that for now :)
     
unityunity