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\$
4
  • 1
    \$\begingroup\$ Have you tried also flipping the children? With something like foreach(Transform child in transform)? \$\endgroup\$ Commented Apr 8, 2014 at 15:31
  • \$\begingroup\$ Yes. I have tried flipping the children. That didn't do the trick. \$\endgroup\$ Commented Apr 8, 2014 at 15:49
  • 1
    \$\begingroup\$ Perhaps try detaching the children before the flip and reattaching after the flip is done? \$\endgroup\$ Commented Apr 8, 2014 at 16:09
  • \$\begingroup\$ That didn't seem to work. \$\endgroup\$ Commented Apr 8, 2014 at 16:30

1 Answer 1

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\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.