Search Unity

Changing PhysicsVelocity during CollisionEvents

Discussion in 'Physics for ECS' started by Epineurien, Jun 3, 2020.

  1. Epineurien

    Epineurien

    Joined:
    Mar 9, 2013
    Posts:
    45
    Hello,

    I'm trying to modify velocity when a collision is detected (to make bumpers and effects like that), but for some reason it doesn't do anything.
    The code is called via SimulationCallbacks.Callback & StepPhysicsWorld.EnqueueCallback, and the loading/saving of PhysicsVelocity is done with ComponentDataFromEntity.
    Traces inside the event show that the velocity is correctly saved, but somehow nothing happen and the velocity is back to normal the following frame. I have no problem modifying other components.
    Is there some specific time where velocity can't be changed, and if so, how can I apply additional physics effects from a collision ?
     
  2. Epineurien

    Epineurien

    Joined:
    Mar 9, 2013
    Posts:
    45
    Self answering : got it to work by making those velocity changes via a EntityCommandBuffer.Concurrent instead.