Search Unity

Resolved Weird Interactions Between Kinematic Bodies in Havok

Discussion in 'DOTS Physics' started by LandonF, Jun 7, 2021.

  1. LandonF

    LandonF

    Joined:
    Mar 1, 2016
    Posts:
    34
    While using Havok physics, my dynamic bodies refuse to collide with a rotating rectangle. Everything works fine in Unity Physics, but I really want to use Havok for optimization purposes.

    I've tried cranking up the solver iterations and changing the simulation steps to 1/120 and it somewhat helps but the dynamic objects still rarely collide with the rectangle. I've attached a video with the issue...

     
  2. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,739
    Kinematic bodies need to be 100% moved/rotated with velocity for their collisions to work properly

    You can use "PhysicsVelocity.CalculateVelocityToTarget" to get a physicsVelocity that would bring a body to a target translation/rotation over the next frame
     
    Last edited: Jun 7, 2021
    steveeHavok and LandonF like this.
  3. LandonF

    LandonF

    Joined:
    Mar 1, 2016
    Posts:
    34
    Ok so, I am trying to make the rotate script work with PhysicsVelocity.CalculateVelocityToTarget() but I'm unsure as to why its not working?

    Here's the code I was using that worked in rotating the objects with a component StirRod:
    Code (CSharp):
    1.     protected override void OnUpdate()
    2.     {
    3.  
    4.         var dt = Time.DeltaTime;
    5.         var tickSpeed = 1f / Time.DeltaTime;
    6.         // Rotate object
    7.         Entities.ForEach((ref Rotation rot, ref StirRod stirComp) =>
    8.         {
    9.             quaternion yRot = quaternion.RotateY(80f * Mathf.Deg2Rad * dt);
    10.  
    11.             rot.Value = math.mul(rot.Value, yRot);
    12.          
    13.         }).Run();
    14.     }
    And here's the code I'm trying to use, now with the CalculateVelocityToTarget():

    Code (CSharp):
    1. [UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
    2. [UpdateBefore(typeof(BuildPhysicsWorld))]
    3. public class RotateObjectECS : SystemBase
    4. {
    5.    
    6.     protected override void OnUpdate()
    7.     {
    8.  
    9.         var dt = Time.DeltaTime;
    10.         var tickSpeed = 1f / Time.DeltaTime;
    11.  
    12.         Entities
    13.         .WithAll<StirRod>()
    14.         .WithoutBurst()
    15.         // Calculate contact events
    16.         .ForEach((ref PhysicsVelocity vel, ref Rotation rotation, in Translation translation, in PhysicsMass mass) =>
    17.         {
    18.             quaternion yRot = quaternion.RotateY(80f * Mathf.Deg2Rad * dt);
    19.             RigidTransform targetTransform = new RigidTransform(math.mul(rotation.Value, yRot), translation.Value);
    20.  
    21.             rotation.Value = math.mul(rotation.Value, yRot);
    22.             vel = PhysicsVelocity.CalculateVelocityToTarget(mass, translation, rotation, targetTransform, tickSpeed);
    23.         }).Run();
    24.     }
    25. }
    26.  
    edit for clarification: The kinematic body isn't moving anymore with the second script
     
  4. LandonF

    LandonF

    Joined:
    Mar 1, 2016
    Posts:
    34
    Never mind, the script above totally works now. I had the body marked as "static" instead of "kinematic" when testing lol. Thank you so much for your help!
     
    petarmHavok, steveeHavok and PhilSA like this.
unityunity