Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Getting animated position in Update

Discussion in 'Animation' started by BakeMyCake, Feb 9, 2021.

  1. BakeMyCake

    BakeMyCake

    Joined:
    May 8, 2017
    Posts:
    175
    Given an animation that changes position, is it possible to get the next animated position in a script?
    Suppose I have a 2d platform that moves up and down and I need the player to move with it, how can I do so?
     
  2. M-Elwy

    M-Elwy

    Joined:
    Jan 28, 2021
    Posts:
    38
    One solution is using physics, create one collider for the player and one for the platform, when the platform moves up the platform collider will push the player's collider up, when the platform moves down the gravity will pull the player down.
    Other solution is parenting the player to the platform, when the platform moves, the player will move with it's parent, but I don't recommend this solution in this case, I mainly use it to make player grab objects (like holding a sword).