- Home /
Playing move animation from fbx file
Hi. I'm newbie in Unity, and have a little problem. I've got a three .fbx file jump.fbx (jump animation) turn.fbx (turn left and right animation) mixed.fbx (some more animation like run, walk etc.) and i've got this script for move (without animation).
#pragma strict
var walkSpeed : float = 7;
var gravity : float = 50;
var rotationSpeed : float = 10;
var yRot : float;
function Update () {
var Controller : CharacterController = GetComponent(CharacterController);
var vertical : Vector3 = transform.TransformDirection(Vector3.forward);
var horizontal : Vector3 = transform.TransformDirection(Vector3.right);
if(Input.GetAxis("Vertical") || Input.GetAxis("Horizontal")){
Controller.Move((vertical * (walkSpeed * Input.GetAxis("Vertical"))) * Time.deltaTime);
Controller.Move((horizontal * (walkSpeed * Input.GetAxis("Horizontal"))) * Time.deltaTime);
}
if(Input.GetAxis("Mouse X")){
yRot += 10 * Input.GetAxis("Mouse X");
}
transform.rotation = Quaternion.Euler(0, yRot, 0);
}
It working, but my charcter doing only default animation from animator controller. So i get this script to get animation movement for my character:
#pragma strict
var walkSpeed : float = 7;
var gravity : float = 50;
var rotationSpeed : float = 10;
var yRot : float;
function Update () {
var Controller : CharacterController = GetComponent(CharacterController);
var vertical : Vector3 = transform.TransformDirection(Vector3.forward);
var horizontal : Vector3 = transform.TransformDirection(Vector3.right);
if(Input.GetAxis("Vertical") || Input.GetAxis("Horizontal")){
animation.CrossFade("walk_normal0", 0.2);
Controller.Move((vertical * (walkSpeed * Input.GetAxis("Vertical"))) * Time.deltaTime);
Controller.Move((horizontal * (walkSpeed * Input.GetAxis("Horizontal"))) * Time.deltaTime);
}else{
animation.CrossFade("ArmatureAction0", 0.2);
}
if(Input.GetAxis("Mouse X")){
yRot += 10 * Input.GetAxis("Mouse X");
}
transform.rotation = Quaternion.Euler(0, yRot, 0);
}
But now i get that error in Unity console:
MissingComponentException: There is no 'Animation' attached to the "jump" game object, but a script is trying to access it.
And i cant move my charcter in game, but default animation works.
PS. I use Unity 4.3 All of .fbx file have charcter model English is my second language, so please be lenient :)
Add Component / $$anonymous$$isc / Animation to the GameObject
Thanks for fast reply! I add Animation component, but now i get this errors:
The animation state ArmatureAction0 could not be played because it couldn't be found! The animation state walk_normal0 could not be played because it couldn't be found!
And that look my GameObject components (i can add only one Animation component, when i've got several animation):
Answer by Pigold11 · Feb 16, 2014 at 01:39 PM
The AnimatoR (!) component works with a totally different animation system called "Mecanim", you don't seem to use it (what I do recommend, so watch this www.youtube.com/watch?v=Xx21y9eJq1U ) but if you want to do it your way you need to add more animations to the AnimatioN (!) component, you do that by opening the Animations arrow and increase the size, so that you can add more animations.
Your answer
Follow this Question
Related Questions
Raycast using Transform.Up issue - FBX Model from Messiah 1 Answer
Making a bubble level (not a game but work tool) 1 Answer
Where did my animation clips go? 0 Answers
How to create animation from FBX at runtime, not in editor! 1 Answer
Problems importing FBX model from 3DS and applying movement 1 Answer