Flotolk
Flotolk

Reputation: 332

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:

Upvotes: 2

Views: 3377

Answers (1)

Flotolk
Flotolk

Reputation: 332

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);
}

Upvotes: 3

Related Questions