Search Unity

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

Discussion in 'Entity Component System' started by uknowunity, Aug 1, 2020.

  1. uknowunity

    uknowunity

    Joined:
    Jul 12, 2018
    Posts:
    15
    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:
    246
    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:
    15
    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:
    246
    If an entity has one of the 6 RotationEuler components and a Rotation component, the EndFrameRotationEulerSystem will handle it for you.