Search Unity

Resolved PhysicsMassOverride still does not allow translation to be changed

Discussion in 'Physics for ECS' started by flyingmylove, Jan 7, 2021.

  1. flyingmylove

    flyingmylove

    Joined:
    Sep 29, 2019
    Posts:
    11
    Hi! I have a question about the usage of PhysicsMassOverride. When I add this component to an Entity, I would like to change its translation just like kinematic body does, but burst still does not allow such option because the original Entity is still labeled with Dynamic body. Would someone provide some hint on how to update the Entity translation when PhysicsMassOverride is attached? Many thanks......
     
  2. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    You should still be able to change the value of the Translation component regardless of the PhysicsMassOverride component. Moving Physics bodies via Translation is not recommended (setting velocities would be better), but it should work.
    Do you have an example of your code where you are changing things or, even better, a simple repo project showing the problem that you can share?
     
  3. flyingmylove

    flyingmylove

    Joined:
    Sep 29, 2019
    Posts:
    11
    Hi, Stevee:

    I think I have found the problem: I should do the translation updates before BuildPhysicsWorld or after EndFramePhysicsSystem. However, I currently find a new problem: if I remove the PhysicsMassOverride (isKinematic = 1), the mass from the function world.GetEffectiveMass becomes 0 ...... Should I somehow do some storage to preserve the old values? Or those extension functions are kind of deprecated.....

    ps: if isKinematic = 0, then the mass is a bit reduced(25%) and the velocity from world.GetLinearVelocity become insanely high.......
     
  4. milos85miki

    milos85miki

    Joined:
    Nov 29, 2019
    Posts:
    197
    Hi @flyingrothschild, could you please double-check that rigidBodyIndex and point you're passing into world.GetEffectiveMass are correct?
    Note that point should be in world space and rigidBodyIndex is index of the body in PhysicsWorld.Bodies array. If you remove/edit components on some entities they might get reshuffled in next frame, so if you shouldn't expect body indexes to stay intact.

    The purpose of PhysicsMassOverride component is to relieve you from saving PhysicsMass data yourself and enable you to easily toggle between dynamic and kinematic body.
     
    petarmHavok and flyingmylove like this.
  5. flyingmylove

    flyingmylove

    Joined:
    Sep 29, 2019
    Posts:
    11
    You are right! I rechecked the rigidBodyIndex and the index does change after I put PhysicsMassOverride component on it. Thank you very much for your help!
     
    petarmHavok likes this.