Search Unity

Freeze rotation in unity physics

Discussion in 'Physics for ECS' started by Deleted User, Aug 12, 2019.

  1. Deleted User

    Deleted User

    Guest

    Is it possible to freeze rotation when using unity physics?
     
  2. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    246
    in the PhysicsMass component, there's a float3 field called "InverseInertia". Set the x, y, and z components to zero to freeze rotation around all axes.
     
    petarmHavok, woskyleo and Eldirfar like this.
  3. woskyleo

    woskyleo

    Joined:
    Sep 2, 2019
    Posts:
    2
    Thanks
     
  4. JPMcWhiskers

    JPMcWhiskers

    Joined:
    Sep 22, 2014
    Posts:
    14
    I know the answer has been posted, but here was my solution for putting it into a System

    Code (CSharp):
    1.  
    2. public class YourSystem : SystemBase
    3.  
    4. protected override void OnStartRunning()
    5.     {
    6.         Entities
    7.             .WithBurst()
    8.             .ForEach((ref PhysicsMass mass, ref YourData characterData) =>
    9.             {
    10.                 mass.InverseInertia.x = 0;
    11.                 mass.InverseInertia.z = 0;
    12.             }).ScheduleParallel();
    13.         base.OnStartRunning();
    14.     }
    15.  
     
    calabi, petarmHavok and steveeHavok like this.