Search Unity

Need help with 2D animations

Discussion in '2D' started by SantiagoRivero24, Jan 21, 2019.

  1. SantiagoRivero24

    SantiagoRivero24

    Joined:
    Jan 16, 2019
    Posts:
    19
    So here's the thing, i want to make a transition from "Still" to "Caminando" ("Walking") and back, the thing is that it works for the first part, it goes to "Still" to "Caminando" but it doesn't go back to "Still" when i'm not walking, here's my code:

    using UnityEngine;

    public class Movimiento : MonoBehaviour
    {

    public Rigidbody2D rb;

    public float sidewaysforce;

    public Animator animator;

    // Update is called once per frame
    void FixedUpdate()
    {
    if (Input.GetKey("a"))
    {
    rb.AddForce(new Vector2(-sidewaysforce, 0));

    animator.SetFloat("Velocidad", sidewaysforce);
    }

    if (Input.GetKey("d"))
    {
    rb.AddForce(new Vector2(sidewaysforce, 0));

    animator.SetFloat("Velocidad", sidewaysforce);
    }
    }
    }

    I know i have to program it so it goes back to still but idk how, please help me.
     
  2. Rockaso

    Rockaso

    Joined:
    Oct 31, 2016
    Posts:
    85
    How did you set up your Animation Controller?
     
  3. SantiagoRivero24

    SantiagoRivero24

    Joined:
    Jan 16, 2019
    Posts:
    19
    No exit transitions and enter "Caminando" if "Velocidad" is Greater than "0.01" and exit if it is less than "0.01"
     
  4. Rockaso

    Rockaso

    Joined:
    Oct 31, 2016
    Posts:
    85
    Try debuging your animation controller by pressing play without window maximized, select the gameobject with the animation and open the animation controller from your assets, how does it look like?