简体   繁体   中英

Get accurate Rotation Angle in Unity3D C#

So I am trying to make a program in Unity simulating a boats movement. This includes what happens when the boat collides with something. While the boat moves just fine, the heading values that I returns aren't in radians or degrees. Here is the code I am using to determine the Heading:

  void getHdg()
  {
    float temp = this.transform.rotation.z;

    craft.ChangeHeading(temp);
  }

Every site that I went to suggested the use of Euler Angles , but from what I saw, they only update on a key press.

I need a way to either:

  • update the heading whenever the boat turns (even on collisions with other objects)
  • or transform the bogus vaules from the transform.rotation code to degrees

there are two issues with the code:

  1. The code is checking for the z axis, not the y
  2. the need to test for Euler Angles which do constantly update

Here is the correct code:

void getHdg()
{
    float temp = this.transform.eulerAngles.y;
    craft.ChangeHeading(temp);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM