Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Bug Animator blocks x movement of rigidbody2D but allows y movement

Discussion in 'Animation' started by Spiele_Spiela, Jan 18, 2021.

  1. Spiele_Spiela

    Spiele_Spiela

    Joined:
    Apr 13, 2020
    Posts:
    3
    Hi,

    I have a Gameobject with an Animator, Rigidbody2D, BoxCollider2D and a Test script

    The Animator has one Animations, that doesn't change the position (wirte defaults is disabled). Apply root motion is enabled. I want to add more animations that will change the position (as this is only a test Project to find a solution to this "bug?").

    Now in the Test script I am now setting velocity to new Vector(1,1) so it should move diagonally up-right. But it doesn't, it only moves up. Disabling the animator results in the correct movement.

    The blinking box ist the one with the animator, both have the same script and I enable the movement at the same time.


    Test script
    Code (CSharp):
    1. public class Test : MonoBehaviour
    2. {
    3.     public bool move;
    4.     Rigidbody2D rb;
    5.  
    6.     private void Awake()
    7.     {
    8.         rb = GetComponent<Rigidbody2D>();
    9.     }
    10.  
    11.     void FixedUpdate()
    12.     {
    13.         if (move)
    14.         {
    15.             //rb.velocity = new Vector2(1f, 0f);
    16.             //rb.velocity = new Vector2(0f, 1f);
    17.             rb.velocity = new Vector2(1f, 1f);
    18.         }
    19.     }
    20. }
     
unityunity