why is my character rotation always 180° after joystick is released.

object will rotate by the joystick angle but when its released rotation is 180. Part of the script :

var joystick : Joystick; //from mobile assets.

function Update () {
var An = Mathf.Atan2(-joystick.position.x,joystick.position.y) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(180 - An,Vector3.up);
}

Because Mathf.Atan2(0, 0) returns zero. (The zero vector doesn’t “point” anywhere, so zero was arbitrarily chosen so the function wouldn’t blow up in this case)

You may want to add a deadzone, where if the joystick deflection is less than some threshold, you don’t turn the character at all. Something like:

if(joystick.position.sqrMagnitude > 0.01) // Tune this float to taste.
{
   var An = Mathf.Atan2(-joystick.position.x,joystick.position.y) * Mathf.Rad2Deg;
   transform.rotation = Quaternion.AngleAxis(180 - An,Vector3.up);
}

The code now won’t be executed unless the joystick has some non-trivial deflection.