- Home /
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
Answer by CheetahSpeedLion · Jul 12, 2017 at 04:13 AM
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.
the jump and run animations works fine with the inputs the main problem is that the colliders dont follow the character when he jumps
I think what you mean is your character animation moves your model up but the transform and all other components stay at y=0 or whatever your ground height is. If that's the case, you might want to go back to your animation and remove the vertical movement and handle that using transform.translate or any other method within Unity. In other words, the vertical movement shouldn't be baked inside the animation.
Areleli
Answer by Merhex · Jul 12, 2017 at 12:02 PM
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.
when i jump the character controller keep it position and dont be in the player position when jumping and after the players jumps he returns to his last position where the jump animation begins
Answer by Hanross · Aug 30, 2018 at 01:51 PM
Did you found the solution ? ,Did you found the solution ?? @Hamilcar-games