1
\$\begingroup\$

I have a character that on start-up is equipped with another gameobject/prefab as a weapon, attaching it to a hand.

void Start() 
{
    handFront = transform.Find ("root/Hip/BodyBone/OverArmFrontBone/UnderArmFrontBone/HandFrontBone/HandFrontMount");

    instance = (GameObject)Instantiate(Resources.Load<GameObject>("VioletClub"), new Vector3(-0.5f,2f,1f), new Quaternion(0f,0f,45f,-45f));
    instance.transform.parent = handFront;
}

As long as I move the character in the initial direction (right) the attached object behaves as it should, staying in the hand no matter the animation played. But when I flip the character, the attached object doesn't flip correctly. In the initial position (standing still) it looks correct but when I start to move the character, the item flips and rotates the wrong way. It does not follow the arm movement like it should.

Correctly attached

This is what I do on flip:

void Flip ()
{   
    facingRight = !facingRight;

    Vector3 theScale = transform.localScale;
    theScale.x *= -1;
    transform.localScale = theScale;

}

Incorrect

When I flip the character back to the right again it all work as it should.

Can anyone help me?

\$\endgroup\$
  • 1
    \$\begingroup\$ Have you tried also flipping the children? With something like foreach(Transform child in transform)? \$\endgroup\$ – MichaelHouse Apr 8 '14 at 15:31
  • \$\begingroup\$ Yes. I have tried flipping the children. That didn't do the trick. \$\endgroup\$ – seddler Apr 8 '14 at 15:49
  • 1
    \$\begingroup\$ Perhaps try detaching the children before the flip and reattaching after the flip is done? \$\endgroup\$ – Tetrad Apr 8 '14 at 16:09
  • \$\begingroup\$ That didn't seem to work. \$\endgroup\$ – seddler Apr 8 '14 at 16:30
2
\$\begingroup\$

You need to rotate the object 180 degrees on the X-axis instead of using scale for this.

Use: http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.