problem with animations running then jumping

im new to animations ^ ^

i have a 3d model “humanoid” and attached to it a character controller
i have 2 animation “run” & “jump”
the run aniamtion i the default state (the game is an endless runner

and have this script attached to the player :

using UnityEngine;

public class player_mov : MonoBehaviour {

private CharacterController cc;

private Animator anim;

public float speed;
// Use this for initialization
void Start () {
	cc = GetComponent<CharacterController> ();
	anim = GetComponent<Animator>();

}

// Update is called once per frame
void Update () {

	cc.Move (Vector3.forward  * speed* Time.deltaTime );

	if (Input.GetKey(KeyCode.LeftArrow)) {

		cc.Move (Vector3.left  * speed* Time.deltaTime );
	}

	if (Input.GetKey (KeyCode.RightArrow)) {

		cc.Move (Vector3.right  * speed* Time.deltaTime );
	}

	if (Input.GetKey (KeyCode.Space)) {

		anim.Play ("JUMP");
	}

}

}

with this i have 2 problems :

1-the jump animations play but dont go back to run animation

2-when i jump and then go back to running the run animation dont start from where the players has completed his jump but from thhe place which he started the jump

so if anyone can explain me in details how to make transitions between animation with custom input

and the problem n’2

n2 problem :

i just found that the character controller dont follow the player when he jumps !

so how to make it follow him

Hi, you’ll need to use collision detection or the transform’s position.

Using collision detection, you would need to tag the ground, then:

void OnCollisionEnter ( Collision collision)
{
if( collision.collider.tag == “Ground”)
anim.Play(“RUN”);
}

or using the transform’s position:

void Update()
{
if( transform.position.y <= 0)
anim.Play(“RUN”);
}

You could use a “grounded” boolean to keep track of this and not let the player jump if it isn’t grounded. Also, you can use Mecanim instead of animator.Play if you need to use more states. Depends how complex you want to go.

What do you mean by following?

And make sure you have set a transition in the Animator between your Running and Jumping state. So it can trigger and exit the other.

Did you found the solution ?
,Did you found the solution ?? @Hamilcar-games