localScale affecting transform.translate in Unity 5.4.0?
Hi there, I'm using localScale to change the direction my player animation is facing, given the axis direction. i.e, If player press left arrow, localScale = new vector3(-1,1,1); if player press right, localScale = new vector3(1,1,1) .
On Unity 5.3 I then used transform.translate(vector.right*speed) to move character right and vector.left to move character left. All worked fine then. Since I installed Unity 5.4, the direction of translate is affected by localScale, i.e., when localScale = -1,1,1 (player face left), and I translate with vector.left, the gameobject moves right, instead of left. If I remove the negative scale, movement works again (gameobject goes to left).
Have anyone noticed this, and if so, any tips on how to fix it (or should I assume this is default behaviour for Unity from now on and should just multiply the direction vector by the localScale)?
Thank you!!
Mark
Same here...
Need Explanation please..
Thank You, Viky
Answer by OsmiousH · Aug 21, 2016 at 02:23 PM
Dear @girhor and @kidastudio
In unity 5.4 If you flip the Local scale You flip the transforms
Will change to
Get It!
so a quick fix is
//JS
if(Input.GetKey("left")){
if(transform.LocalScale > 0){
transform.Translate(0,0,-1);
}
else{
transform.Translate(0,0,1);
}
}
if(Input.GetKey("right")){
if(transform.LocalScale > 0){
transform.Translate(0,0,1);
}
else{
transform.Translate(0,0,-1);
}
}
This new script will change the transform according to local scale
PLZ inform me about any bugs
Answer by maltadirk · Sep 24, 2016 at 02:34 PM
Hi all,
So the transform happen with both test codes that follow, however on moving left its like his doing a moonwalk. Again this problem started specifically on v5.4. Could it be something changes with the Animator? It looks different.
Test 1:
Vector3 thisScale = this.transform.localScale;
thisScale.x *= -1;
this.transform.localScale = thisScale;
Test 2:
if (facingRight) // RIGHT
{
transform.eulerAngles = new Vector3 (0, 0, 0);
}
else
{
transform.eulerAngles = new Vector3 (0, 180, 0);
}
Your answer
