Hey guys!
I have had a little controller made for a while and on my development machine it runs perfect. When testing some other features of my game on another one of my machines however it appeared to be having an issue. After a few hours of debugging I was able to figure out exactly what the issue is.
Let me break it down as simple as possible. I have a character that is able to look left and right from different button input. When the character is looking left they rotate -90 degrees. When they press the button again they rotate back 90 degrees. For the right it rotates 90 degrees, then back -90.
I print the value of transform.forward.x to my UI and it shows that when the character has rotated to the left their transform.forward.x equals -1.0 and when they rotate to the right it equals 1.0.. The problem I am having is, on my other computer, when I rotate left it shows -1.0 and everything is fine and good, but when I rotate right it shows 1.0 for a split second then it shows .999999 and because the value is not greater than or equal to 1, the controller âfreezesâ. I made it part of the Input.GetButtonUp conditional that the transform.forward.x be greater than or equal to 1.0..
I will take out some flags and other variables that make it more confusing to parse, but in a nutshell the following is how my controller works.
function Update()
{
if(Input.GetButtonDown("Look Left"))
{
RotateObject(transform.rotation, Quaternion.Euler(transform.rotation.eulerAngles + Vector3.up * -90), 0.8);
}
if(Input.GetButtonUp("Look Left") && transform.forward.x <= -1.0)
{
RotateObject(transform.rotation, Quaternion.Euler(transform.rotation.eulerAngles + Vector3.up * 90), 0.8);
}
if(Input.GetButtonDown("Look Right"))
{
RotateObject(transform.rotation, Quaternion.Euler(transform.rotation.eulerAngles + Vector3.up * 90), 0.8);
}
if(Input.GetButtonUp("Look Right") && transform.forward.x >= 1.0)
{
RotateObject(transform.rotation, Quaternion.Euler(transform.rotation.eulerAngles + Vector3.up * -90), 0.8);
}
}
function RotateObject(startRot: Quaternion, endRot: Quaternion, rotateTime:float)
{
var i:float = 0.0;
var rate:float = 1.0/rotateTime;
while(i < 1.0)
{
i += Time.deltaTime * rate;
transform.rotation = Quaternion.Lerp(startRot, endRot, Mathf.SmoothStep(0.0, 1.0, i));
yield;
}
}
So to recap, the issue is, this code runs perfect on my development machine, but when I try it out on any of my other machines, the transform.forward.x ends up equaling .999999 after a rotation to the right, which effectively locks the controller.
Thanks for any insight or assistance guys! If you need to see more of the flags let me know, but I have a good reason to believe those flags are not to blame.
UPDATE: I had only been executing my code on my development computer via Unity. I executed one of the build.exeâs and it did the same thing. When I look right, the transform.forward.x ends up equaling .99999 instead of 1.0 when I run it in Unity.
UPDATE #2: I was able to fix this.. by setting my Unity to compile an x86 build. For some reason when I compiled this as x86/x64 it was breaking. Setting it to x86 makes it run perfect, just like in the editor. If anyone can hint as to why that might be, that would be awesome! But for now I am content with the results, moderators can remove this thread.