Answers for "Why won't the X axis of the player lock like the Z axis?"
http://answers.unity.com/questions/1147945/why-wont-the-x-axis-of-the-player-lock-like-the-z.html
The latest answers for the question "Why won't the X axis of the player lock like the Z axis?"Answer by brunocoimbra
http://answers.unity.com/answers/1148796/view.html
Don't use Time.deltaTime in Lerp. I know, the documentation gives an example doing it that way, but there is no need to use it.
Lerp just pick the value relative to value x and y passed to it, so having X = 2 and Y = 10, we have:
If Mathf.Lerp(x, y, 0), we receive 2 (the first value).
if Mathf.Lerp(x, y, 1), we receive 10 (the last value).
if Mathf.Lerp(x, y, 0.5f), we receive 6 (the middle point between value x and y).
so if you want to copy the value, don't use Time.deltaTime, as it would give you a somewhat random value next to 0.02, what would not result in a number a little bit bigger than the first one passed to the fuction..
You can use it:
float x = Mathf.Lerp(other.transform.position.z, transform.position.z, 0)
or it:
float x = other.transform.position.z
Also, change those:
if(other.transform.rotation.y == 180)
if(other.transform.rotation.y == 90 || other.transform.rotation.y == 270)
to those:
if(other.transform.rotation.y % 180 == 0 || other.transform.rotation.y == 0)
if(other.transform.rotation.y % 180 != 0 && other.transform.rotation.y % 90 == 0)
the difference? checking if the rotation is a multiple of 180 or 90 is better, as it will fit in when the rotation is negative too, what seems to be your problem, as a rotation of -90 would NOT lock the X axis.Mon, 29 Feb 2016 19:07:34 GMTbrunocoimbra