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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Prefabs jump to same location

Discussion in 'Scripting' started by babasuter, Nov 14, 2016.

  1. babasuter

    babasuter

    Joined:
    Feb 18, 2014
    Posts:
    10
    My students and I want to animate a simple capsule (moving vertically up and down), then duplicate it as part of the roll-a-ball tutorial. Problem is: they all jump to the original position of the first capsule.

    How do we animate and make the capsule prefab without them doing this?
    Here's a video of how we animated it, made the prefab, duplicated it, and then the jumping to same location problem.
     
  2. vothka

    vothka

    Joined:
    Mar 27, 2015
    Posts:
    59
    Hello Sir,

    That is not very surprising, you are storing positions in the animation which will be applied as soon as you start the animation.

    To achieve what you want you can simply create an empty gameobject and set you capsule with your animation as a child to the empty object. Now you can move the empty object as you want and the child will perform its animation in relation to the parent.

    so in short: create the empty GO / capsule object, set the position of the capsule relative to the empty GO to 0,0,0 - now create your animation for the capsule -> done

    hope this helps

    vothka
     
    babasuter likes this.
  3. babasuter

    babasuter

    Joined:
    Feb 18, 2014
    Posts:
    10
    Ah hah! That worked perfectly. Thank you Vothka