Search Unity

How to hide the tranlate transition to the first part of the animation?

Discussion in 'Animation' started by spacelyjoe, Sep 22, 2014.

  1. spacelyjoe

    spacelyjoe

    Joined:
    Aug 19, 2013
    Posts:
    3
    For one of my gameobjects I have an animation that starts at a different xy than the current position of the object before the animation runs, but when I start the animation it translates into the new x y the animation starts on instead of 'teleporting' it to the new x y which is what I want it to do. Any way to do this?
     
  2. spacelyjoe

    spacelyjoe

    Joined:
    Aug 19, 2013
    Posts:
    3
    still haven't been able to figure this out. anyone? If you don't understand I can be more specific but I think I explained it correctly. I just want to hide the translation of the original x y to the x y of the first part of the animation.
     
  3. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    The normal workflow is to start the animation where your gameobject is.

    But if you want to teleport your object you can set the position/rotation/scale before playing your animation with
    transform.position = myPosition;
    transform.rotation = myRotation;


    The tricky part is to extract the data from the clip, I would do it in the editor with a script.

    To get the value you can Sample the clip with GameObject.SampleAnimation() and then retrieve the sampled data on your gameobject(SampleAnimation write the animated value on the game object). And finally store the data on some MonoBehaviour script on your game object, at runtime you would need to read this back and set it in your transform just before you want to play the animation.