Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to stop a trigger jump animation when player colliding the ground?

Discussion in '2D' started by Nevender, Oct 11, 2017.

  1. Nevender

    Nevender

    Joined:
    Oct 5, 2017
    Posts:
    1
    Hello there!

    I'm a new unity's user, and i'm triying to make a little 2D plateformer.
    I can controle my player but i have a little problem with my jump.

    I made it with a trigger in animator, it works, but i want to stop the animation when player touching the ground.

    The best will be to keep the last jump's frame prep until the player touch the ground, and after stop it.

    I have a collider2D on a gameObjet who's attached to the player with this code:

    Code (CSharp):
    1.  void OnTriggerEnter2D (Collider2D col)
    2.     {
    3.         if (col.gameObject.tag == "Sol" || col.gameObject.tag == "Plateforme")
    4.         {
    5.             transform.parent.GetComponent<playerController>().isGrounded = true;
    6.             Audio.pitch = 0.7f;
    7.             Audio.volume = 0.7f;
    8.             Audio.PlayOneShot(soundGround);
    9.         }
    10.     }
    11.  
    12.     private void OnTriggerExit2D(Collider2D collision)
    13.     {
    14.         transform.parent.GetComponent<playerController>().isGrounded = false;
    15.     }
    I know how to stop boolean, but is it possible with trigger?

    Thanks for your help and sorry if my english is bad :p

    Etienne
     
  2. hlw

    hlw

    Joined:
    Aug 12, 2017
    Posts:
    250
    Maybe you can make a trigger in your animation that starts the "iddle" animation and trigger it when you touch the ground