So I’m attempting for the first time to do a whole lot of javascripting myself for a unity project. I am creating a little 2-d style game with very simple back and forth movement. I actually have this working…the movement is fine, and I was able to get the character rotated the correct way by using:
transform.localEulerAngles.y=90;
…which was the “right” direction, 270 the left.
Now i’m trying to make the character “turn” until he faces the opposite direction. I have been using this to make him turn:
transform.Rotate(Vector3.up*Time.deltaTime*100);
It does work…now I want him to turn only if he’s not facing the direction he should be…so I tried THIS, and here is where I’m having the problem:
if (!(transform.localEulerAngles.y==90))
{
transform.Rotate(Vector3.up*Time.deltTime*100);
}
Any thoughts as to why the player would rotate right from the start, even though the angle is 90 degrees right from the start? Any better methods? I’m sure there is a much more efficient way to achieve this…thanks!