Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Euler problem

Discussion in 'Project Tiny' started by Anton_hc, Mar 5, 2019.

  1. Anton_hc

    Anton_hc

    Joined:
    Jul 6, 2012
    Posts:
    15
    i try to rotate transform by direction of velocity.

    In unity work perfect:

    float angle = Mathf.Atan2(velocity.y,velocity.x) * 180 / Mathf.PI;
    transform.rotation = Quaternion.Euler(0, 0, angle);

    but in tiny i get a spinner as a result =)

    let vel = this.data.velocity.velocity;
    let angle = Math.atan2(vel.y, vel.x) * 180 / Math.PI;
    this.data.rotation.rotation.setFromEuler(new Euler(0,0,angle));

    angle calculate correctly, problem with setFromEuler: if i try setFromEuler(new Euler(0,0,90));, as a result i get ~100 degrees.

    What i do wrong?
     
  2. Rupture13

    Rupture13

    Joined:
    Apr 12, 2016
    Posts:
    130
    I couldn't get setFromEuler to work either. I did find this one, that works for me:

    Code (CSharp):
    1. // after calculating your vel and angle:
    2. this.data.rotation.rotation.setFromAxisAngle( new Vector3(0,0,1), (angle / 180) * Math.PI );
     
    Anton_hc likes this.
  3. Anton_hc

    Anton_hc

    Joined:
    Jul 6, 2012
    Posts:
    15
    thank you! This means that angles are not measured in degrees. It's radians. I think it's a bug and should be like unity style.
     
    sniffle63 likes this.