- Home /
Character Position Moved after Animation assigned
My character position is moved after an animation is assigned.
The character GameObject
is assigned with Animation
, RigidBody
, Capsule Collider
and a C# Script
Component.
The C# Script (animation part) is as follow:
public class MyCharacter : MonoBehaviour {
// Animations
public AnimationClip idleAnimation;
public AnimationClip slideAnimation;
public AnimationClip runAnimation;
public AnimationClip jumpPoseAnimation;
private Animation charAnimation;
enum CharacterState {
Idle = 0,
Running = 1,
Sliding = 2,
Jumping = 3,
}
private CharacterState charState;
void Start () {
charState = CharacterState.Running;
charAnimation = gameObject.GetComponent<Animation>();
if(!charAnimation) {
Debug.Log("No Animation Component.");
} else {
AnimationEvent syncRunEvent = new AnimationEvent();
syncRunEvent.time = runAnimation.length;
syncRunEvent.functionName = "SyncRunAnimation";
runAnimation.AddEvent(syncRunEvent);
}
}
void Update () {
// Animations
if(charAnimation) {
if(charState == CharacterState.Jumping) {
charAnimation.CrossFade(jumpPoseAnimation.name);
} else if(charState == CharacterState.Sliding) {
charAnimation.CrossFade(slideAnimation.name);
} else {
charAnimation.CrossFade(runAnimation.name);
}
}
}
void SyncRunAnimation() {
Debug.Log("Sync Run");
transform.position += new Vector3(0, 3, 0);
}
}
Before assigning the animation, the character is standing in the ground at position (0, 0.6, 0)
. After assigning, the character submerges INTO the ground, stuck; position changed to (0, -0.75, -0.55)
. How can I control the animation position ?
Note: I tried to use SyncEvent
to move up ( increase Y axis ), but it does NO effect at all.
UPDATE This only happens when Animation is set to Legacy. If I set the animation to Generic, it has no problem, but Console issues errors :
The AnimationClip 'run' used by the Animation component 'MyCharacter' must be marked as Legacy.
and the animation could not be played. How can I make it work with Generic animation / correct position with Legacy animation ?
UPDATE 2 Here is a simplified version of the scene, WITHOUT any script.
Before I hit the "PLAY" button
After I hit the "PLAY" button
So the problem is not related to codes, right ?
Sounds like it might be a scaling issue between the model scale and the scale of the animation - that often has that effect for me.
just updated the question with screenshot. How can I check if it is a "scaling" issue ?
Answer by raptorkwok · Feb 17, 2014 at 06:34 AM
To solve this issue, I removed the Position keyframes in Animation panel in Unity 3D.
Your answer
![](https://koobas.hobune.stream/wayback/20220613133345im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I use a joystick for a mobile app to control specific limbs of a character? 0 Answers
What's the best way of setting up a FPS character? 1 Answer
my prolem with Unity Humanoid joint articulation 0 Answers
Does Unity support FBX files directly from MotionBuilder? 0 Answers
2D physics animation. How do I animate a character with physics 1 Answer