- Home /
FPSInputController and Character Animation
Hi people, I have a doubt about the FPSInputController script. If you make a capsule, to be able to move, and rotate around, how do you manage your character's animation?.
After I make the capsule, add everything the FPSInputController controller tells you to do, I add my character and make it child of the capsule. Now, the capsule responds to WASD, mouse look and jump. So.. how can I make now so when I press W, the capsule moves AND the character walk animations plays just like it's supposed to?
I tried with:
function LateUpdate () {
if (Input.GetKey ("w")){
animation.Play("WalkINPLACE");
}
}
Now, you can see that my animation's name is WalkInPlace, because if the capsule is moving forward... then the animation has to occur on the same place right?
I just don't thing this is the way it's supposed to make this work.
Am I missing an important part here? Do I actually have to script every key, assing them to an animation and time the capsule movement with the animation or is there an easier way?
Thanks very much!
Answer by roamcel · Oct 08, 2011 at 04:48 PM
If you use that code in a script that you add to the actual model in your game object, then it'll work, since it'll automatically defer the 'animation' component of the model.
The possibly best way to do that is however slightly different:
declare a public variable
public Transform mymodel;
in your fpsinputcontroller script
drag the model, the child of your gameobject in the scene, into the 'mymodel' slot you just added
insert that code you have in your input controller, with a slight change: instead of your animation... line, type
mymodel.animation.Play("WalkINPLACE");
Additionally, you most certainly will have to set a wrapmode for the animations, in the Start function. Specifically,
mymode.animation["WalkINPLACE"] = WrapMode.Loop;
And don't forget to create a new prefab out of the new game object in the scene.
$$anonymous$$mmmm I will test it right away. I'll let you know, thanks!
Whenever I add the line -> public Transform mymodel; -> I get this error "Unexpected token: Transform."
And when I add -> mymodel.animation["WalkINPLACE"] = Wrap$$anonymous$$ode.Loop; -> It gives me this error "Property 'UnityEngine.Animation.Item' is read only."
What's wrong here? (I'm working with Javascript if it's any help)