Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How would I move a game object vertically using an animation from current position?

Discussion in 'Animation' started by Blankdud, Aug 31, 2022.

  1. Blankdud


    Dec 7, 2015
    I have a group of objects that sit in a row. I've set up an Animation Controller on them and when a trigger is hit, I want to move a single object vertically to visually separate it from the group from where it is currently located.

    My Animation Controller has two animations, "Idle" and "Selected". The "Selected" animation uses the game objects transform.y property to move the object and that works fine. The issue is that the values are static and I cannot move the game object at all (like its locked in place). Is there any way to allow the game object to be placed anywhere and have the animation move it from that location?

    I basically just want to achieve a "lift" affect. I could achieve this by modifying my sprite sheet to just have the sprite "higher" but that seems kind of silly.
  2. Unrighteouss


    Apr 24, 2018
    I answered a similar question here:

    The reason the object is stuck in place is because you're trying to control it both with animation and script (you also won't be able to move it in the scene while the game is running). Animations take priority over everything else, so if an object's position is animated, you won't be able to move it via other means.

    The easy way around this is to create an empty parent object and move that around instead. The position of the child will follow, and any animations the child has will be relative to the position of the parent.

    Just check out the video in the link I posted for a demonstration.