Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Change X position in animator that plays at Y.

Discussion in '2D' started by Agent003, Dec 25, 2019.

  1. Agent003

    Agent003

    Joined:
    Sep 7, 2018
    Posts:
    55
    Hello,
    I have a sprite with a animator controller, it moves from 7 to 0 in Y direction, i want to change X randomly (via script).
    so i starts for X = 1 and Y from 7 to 0, in the next cycle it starts from X = 4 and Y from 7 to 0, like that i mean.
    Every time i change X, when the animation start, the sprite get snapped to X = 0;
     
  2. Primoz56

    Primoz56

    Joined:
    May 9, 2018
    Posts:
    369
    animations will reset positions to what you've set them at in the animation. either move it by script or by animator but not both at same time. One option is to set an animation variable and move the Y position of the character accordingly (probably through layers), or alternatively, move the X position of the animation too.
     
  3. Agent003

    Agent003

    Joined:
    Sep 7, 2018
    Posts:
    55
    I have no idea about layers, so i had to create a parent for my object (which become a child now), the i can set the x position to new value every cycle and the animation plays at the same y position.