Search Unity

[Duplicated]DOTS PhysicVelocity.Angular is in Motion Space Instead of World, Unlike Monobehaviour

Discussion in 'DOTS Physics' started by Extrys, Mar 23, 2020.

  1. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    227
    Im having a few problems trying to make an object to get an angularVelocity needed to reach a determined orientation in DOTS

    But seems like the AngularVelocity gets applied in MotionSpace, instead of World Space.

    anyone knows a workaround for aplying an angularVelocity in World Space instead?

    This is what i have, but any of the following is working, does someone knows what im doing wrong? Thanks
    Code (CSharp):
    1.  
    2. public class AngularVelocitySystem : JobComponentSystem
    3. {
    4.     public int operationId;
    5.     protected override JobHandle OnUpdate(JobHandle inputDeps)
    6.     {
    7.         if (Input.GetKeyDown(KeyCode.Alpha1)) operationId = 0;
    8.         if (Input.GetKeyDown(KeyCode.Alpha2)) operationId = 1;
    9.         if (Input.GetKeyDown(KeyCode.Alpha3)) operationId = 2;
    10.         int operation = operationId;
    11.         return Entities.ForEach((ref PhysicsVelocity vel, in LocalToWorld world) =>
    12.         {
    13.             float3 worldAxis = math.float3(0, 1, 0);
    14.             float3 worldToLocal = math.mul(math.inverse(world.Rotation), worldAxis);
    15.             float3 worldToLocal2 = math.rotate(math.inverse(world.Value), worldAxis);
    16.             float3 worldToLocal3 = math.rotate(world.Value, worldAxis);
    17.  
    18.             float3 selected = default;
    19.             switch (operation )
    20.             {
    21.                 case 0: selected = worldToLocal; break;
    22.                 case 1: selected = worldToLocal2; break;
    23.                 case 2: selected = worldToLocal3; break;
    24.                 default: break;
    25.             }
    26.  
    27.             float3 angVel =  math.normalize(selected) * math.radians(360);
    28.             vel.Angular = angVel;
    29.         })
    30.         .WithAll<AngleRotatorTag>()
    31.         .Schedule(inputDeps);
    32.     }
    33. }
     
unityunity