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. Dismiss Notice

Move object 2D (have animation) to position random

Discussion in '2D' started by David James, Apr 17, 2015.

  1. David James

    David James

    Joined:
    Jan 29, 2015
    Posts:
    61
    How to Move object 2D to position A with animation,
    I try used transform.Position = new vector3 (); can't move with animation .
    I remove animation it move !
    how to fix it? thank !
     
    EugeneVlasov likes this.
  2. codeedward

    codeedward

    Joined:
    Dec 19, 2014
    Posts:
    93
    Good question! +1
    I also do not know.
    I have solution only to simple animations. For example if You want to scale && move && change alpha Your game object You could use LeanTween and do it from code. But with animation I do not know. It will be greate if somebody could give better solution and solution with normal unity animation. Also thanks :)
     
    EugeneVlasov and David James like this.
  3. David James

    David James

    Joined:
    Jan 29, 2015
    Posts:
    61
    I think this problem can't not fix ...
     
    EugeneVlasov likes this.
  4. Kuan

    Kuan

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    87
    David, is you animation affecting your transform.position? If that's the case, the animation will always override your script's manipulation of the transform.
     
  5. David James

    David James

    Joined:
    Jan 29, 2015
    Posts:
    61
    Nice, but how to fix it ?
     
    EugeneVlasov likes this.
  6. der_r

    der_r

    Joined:
    Mar 30, 2014
    Posts:
    259
    Make a new empty GameObject and move it close to the animated one. Then make the animated one a child of the empty one by dragging it beneath it in the hierarchy. Move the empty one and it will drag around your animation. Cheers!
     
  7. Kuan

    Kuan

    Unity Technologies

    Joined:
    Jul 2, 2014
    Posts:
    87
    der_r's solution is spot on. It will solve your problem.

    The root cause of your problem is the animation is affecting your object's position. You can check out your animation to see if the animating of position is necessary.
     
  8. David James

    David James

    Joined:
    Jan 29, 2015
    Posts:
    61
    Thanks all you. I'm trying :)
     
  9. codeedward

    codeedward

    Joined:
    Dec 19, 2014
    Posts:
    93
    Good idea! :)
     
    EugeneVlasov likes this.