4
\$\begingroup\$

I created and animated a sledgehammer in Blender 2.67b using an armature. The sledgehammer has one animation (created using the Action Editor) called "Idle". I parented the imported sledgehammer to an empty GameObject and set the sledgehammer's position to (0, 0, 0). I then moved the parent GameObject to where I want it in the scene. When I launch the game, the animation plays but the sledgehammer child always re-positions itself to be at the global origin, no matter where I place the parent GameObject. See the image below:

animated gameobject mispositioned

Notice how the sledgehammer's position goes from (0, 0, 0) to (-1087, -3, -1149).

The armature has a single bone and has the sledgehammer object as a child. I've spent about 4 hours looking this up on the Internet, but it seems like parenting the animated mesh to an empty GameObject worked for everyone else except me. Anyone else experience this? I've tried both .fbx and .blend files.

\$\endgroup\$
2
  • \$\begingroup\$ In Blender, try hitting Ctrl+A with your object selected, then choose Location. Does that help? \$\endgroup\$
    – House
    Aug 12, 2013 at 3:11
  • \$\begingroup\$ I tried applying the Location/Rotation/Scale early on, didn't fix it. Good suggestion though! I have a tendency to neglect things like that \$\endgroup\$ Aug 12, 2013 at 3:17

1 Answer 1

1
\$\begingroup\$

You can solve this programatically for now. A small script will update the position before the draw call to keep the sledgehammer in the position of your Parented game object. Drag the GameObject parent onto the inspector after applying this script:

UnityScript:

#pragma strict

var localOrigin : GameObject;

function Start () {
    transform.position = localOrigin.transform.position;
}

function LateUpdate () {
    transform.position = localOrigin.transform.position;
}

C#

public GameObject localOrigin;

void Start () {
    transform.position = localOrigin.transform.position;
}

void LateUpdate () {
    transform.position = localOrigin.transform.position;
}

Hope it helps.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .