Search Unity

Switch to Animation on any state

Discussion in 'Animation' started by kutayxx, Feb 11, 2021.

  1. kutayxx

    kutayxx

    Joined:
    Sep 19, 2020
    Posts:
    6
    I have an animator that has 3 states: idle,walking and running. Character switches between these 3 animations without any problem. But i also want to add a swimming animation state. I detect collision with water and player with this:
    Code (CSharp):
    1. void OnTriggerEnter(Collider other)
    2.     {
    3.         if (other.gameObject.CompareTag("water"))
    4.         {
    5.             Debug.Log("water entered");
    6.             animator.SetBool("isSwimming", true);
    7.         }
    8. void OnTriggerExit(Collider other)
    9.     {
    10.         if (other.gameObject.CompareTag("water"))
    11.         {
    12.             Debug.Log("water exited");
    13.             animator.SetBool("isSwimming", false);
    14.         }
    How should i set up the animator so player can switch to Swimming animation no matter what state it currently in?
    Player switch to walk if "move buttons" pressed, and switch to running if "move buttons"+Lshift pressed
    I will first add "floating on water" animation if player isn't moving but on water. After that i will add swim animation if player is on water + moving.
    1.png
     
  2. M-Elwy

    M-Elwy

    Joined:
    Jan 28, 2021
    Posts:
    38
    Why don't you create transition from each state to "floating on water" state with condition "isSwimming" is True? and create transition back to "Breathing Idle" if "isSwimming" is False
     
    kutayxx likes this.
  3. kutayxx

    kutayxx

    Joined:
    Sep 19, 2020
    Posts:
    6
    I found a similar solution, it looks like it's working now, thanks anyway