I have a rigged 2D character with Sprites And Bones in Unity and I use inverse kinematics to animate it.
But if I want to flip the X-axis, my character go berserk :
I have a script attached to "Karateka", containing a simple Flip()
function :
public void Flip(){
facingRight = !facingRight;
Vector3 karatekaScale = transform.localScale;
karatekaScale.x *= -1;
transform.localScale = karatekaScale;
}
- "Karateka" is just a container for bones, sprites and IK targets
- "Skeleton" contains the Skeleton script from Sprite And Bones
- "Right leg bone", "Right lower leg bone", etc. have bone and IK scripts
- "Right leg", "Right lower leg", etc. are the sprites
- "IK" contains all the IK targets
I have the same kind of effect with an other IK script, Simple CCD, from Unite 2014 - 2D Best Practices In Unity, so I may just do something stupid.
What can I do to properly flip my character?
EDIT (for Mark) :
I got it to work using this :
public void Flip(){
facingRight = !facingRight;
/*
Vector3 karatekaScale = transform.localScale;
karatekaScale.x *= -1;
transform.localScale = karatekaScale;
*/
GameObject IK = GameObject.Find ("IK");
GameObject skeleton = GameObject.Find ("Skeleton");
Vector3 ikScale = IK.transform.localScale;
ikScale.x *= -1;
IK.transform.localScale = ikScale;
if (facingRight) {
skeleton.transform.localEulerAngles = new Vector3(skeleton.transform.localEulerAngles.x, 180.0f, skeleton.transform.localEulerAngles.z);
} else {
skeleton.transform.localEulerAngles = new Vector3(skeleton.transform.localEulerAngles.x, 0.0f, skeleton.transform.localEulerAngles.z);
}
}