Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

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

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

  1. Extrys

    Extrys

    Joined:
    Oct 25, 2017
    Posts:
    324
    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. }