- Home /
How to link up animations with the first person controller(not answered yet!)
I used the first person controller unity asset as a third person controller by dragging the camera behind the capsule and i replaced the capsule with my model. I now want to hook up my model animations with first person controller, so when the first person controller moves forward my model plays the run animation or jumping pays the jump animation. The models animations are: "Run" "Standing" "Jump" "Falling". Can someone please help
Answer by Cherno · May 15, 2014 at 03:12 PM
The gameObject that has the mesh with your character model and animations needs an animatoion component that has all the animation clips stored. Then it's just a matter of playing the animations you want on that gameObject, using animation.Play or animation.Crossfade.
I have done that but the animation for run doesnt work when going right,left,backwards so i used transform.rotate but that didnt work out too well same with the jumping, half the time the model doesnt play the animation when using play or crossfade
First of all, check if all animation clips are imported correctly. After that, put Debug.Log("this works"); lines into your code whenever an animation is played so you know if something doesn't work right.
the animations work its just that lets say im hold "D" and the player is moving to the right and playing the run animation but i want to switch to pressing "E" so i press "E" and the play moves left but half the time doesnt play the animation Run.
I am not sure if this is going to work, but I think you can try this one out: If you are using C#, try to use GetButtonUp after GetButtonDown or Get$$anonymous$$eyDown, and make "GetButtonUp" stop running the animation, thus if you press another key the animations won't interfer
ive done that with Get$$anonymous$$eyUp but thats what messes up my animations. This is the problem i think. If you are holding A for example and then you press D whilst holding A and then let go of A about a second later after pressing D, the model will go to the direction of D (in the fps controller, right) but it will not play the run animation because get the Get$$anonymous$$eyUp of A will tell the model to stop playing the run animation even though Get$$anonymous$$eyDown of D is saying Play the run animation. Here is the script. using UnityEngine; using System.Collections;
public class Playermisc : $$anonymous$$onoBehaviour {
public GameObject maincamera;
public GameObject player;
public float turnSpeed = 1.0f;
public float time = 1f;
public float speed = 1f;
public bool defaultView = true;
public bool leftView = true;
public bool rightView = false;
// Use this for initialization
void Start ()
{
animation.Play("Standing");
animation["Falling"].speed = 0.42f;
animation["Jump"].speed = 1.2f;
animation["Run"].speed = 0.8f;
Screen.lockCursor = true;
defaultView = true;
leftView = true;
rightView = false;
}
// Update is called once per frame
void Update ()
{
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape))
{
player.GetComponent<$$anonymous$$ouseLook>().enabled = false;
maincamera.GetComponent<$$anonymous$$ouseLook>().enabled = false;
}
if(Input.Get$$anonymous$$ouseButtonDown(0))
{
Screen.lockCursor = true;
player.GetComponent<$$anonymous$$ouseLook>().enabled = true;
maincamera.GetComponent<$$anonymous$$ouseLook>().enabled = true;
}
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.W))
{
animation.CrossFade("Run");
}
if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.W))
{
animation.CrossFade("Standing");
}
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.D))
{
animation.CrossFade("Run");
transform.Rotate(0,90,0);
}
if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.D))
{
animation.CrossFade("Standing");
transform.Rotate(0,-90,0);
}
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.A))
{
animation.CrossFade("Run");
transform.Rotate(0,-90,0);
}
if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.A))
{
animation.CrossFade("Standing");
transform.Rotate(0,90,0);
}
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.S))
{
animation.CrossFade("Run");
transform.Rotate(0,180,0);
}
if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.S))
{
animation.CrossFade("Standing");
transform.Rotate(0,180,0);
}
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))
{
animation.CrossFade("Jump");
}
}
}