Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
In Blender, try hitting Ctrl+A with your object selected, then choose Location. Does that help? –  Byte56 Aug 12 '13 at 3:11
    
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 –  Ryan Berserkguard Nørby Aug 12 '13 at 3:17

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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