Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted Changing rotations of entity changes also scale. How to change only rotation of an entity?

Discussion in 'Data Oriented Technology Stack' started by uknowunity, Aug 1, 2020.

  1. uknowunity

    uknowunity

    Joined:
    Jul 12, 2018
    Posts:
    13
    Hi,

    I am trying to rotate and entity but it shows weird numbers on the LocalToWorld component. This is the code:

    Code (CSharp):
    1.        
    2. var rot = new Rotation { Value = new quaternion(90, 0, 0, 1) };
    3. entityManager.SetComponentData(CurrentEntity, rot);
    upload_2020-8-1_15-34-41.png

    How can I change rotation without changing any scale on the LocalToWorld component?

    Greets and thanks
     
    Last edited: Aug 1, 2020
  2. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    143
    Quaternions don't work like euler angles. The easiest way to apply euler angle rotations to an entity is to add one of the RotationEuler components to the entity and edit that component.
     
  3. uknowunity

    uknowunity

    Joined:
    Jul 12, 2018
    Posts:
    13
    Thanks! I forget quaterion is really different from eular.

    I got it working with quaterion, is this an good approach for it? Im turning an entity 90 degrees

    Code (CSharp):
    1.  Quaternion oldRotation = entityManager.GetComponentData<Rotation>(CurrentEntity).Value;
    2.  
    3. var newRotation = new Rotation { Value = Quaternion.Euler(0, oldRotation.eulerAngles.y + 90, 0)};
    4.          
    5. entityManager.AddComponentData(CurrentEntity, newRotation);
     
  4. TRS6123

    TRS6123

    Joined:
    May 16, 2015
    Posts:
    143
    If an entity has one of the 6 RotationEuler components and a Rotation component, the EndFrameRotationEulerSystem will handle it for you.
     
unityunity