Hey Y’all,
I’m trying to rotate a Vector2 that starts at (1, 0). This code seems correct, and in fact checking the heading with Debug.Log(newHeading) and Debug.Log(this.heading) both confirm that the calculation is being done correctly.
HOWEVER!! the actual value of the heading that appears serialized in the inspector is something completely different (but consistent every time) that the object will actually use as its heading value. Here’s a snippet of what I’m working with:
Vector2 newHeading = heading;
if (behaviorList[i].values[0] == "0") { // TURN LEFT
newHeading = new Vector2(heading.x * Mathf.Cos(Mathf.Deg2Rad*90) - heading.y * Mathf.Sin(Mathf.Deg2Rad*90),
heading.x * Mathf.Sin(Mathf.Deg2Rad*90) + heading.y * Mathf.Cos(Mathf.Deg2Rad*90));
Debug.Log("after left rotation, " + newHeading);
} else { // TURN RIGHT
newHeading = new Vector2(heading.x * Mathf.Cos(Mathf.Deg2Rad*(-90)) - heading.y * Mathf.Sin(Mathf.Deg2Rad*(-90)),
heading.x * Mathf.Sin(Mathf.Deg2Rad*(-90)) + heading.y * Mathf.Cos(Mathf.Deg2Rad*(-90)));
Debug.Log("after right rotation, " + newHeading);
}
this.heading = newHeading;
}
And this image shows what I mean – the heading is calculated correctly, yet the value that appears in the inspector is completely different [edit: forum will only let me upload one image, this is the more important one]:

Any help would be appreciated!! I have truly no idea what’s happening.
