Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by AntLewis · Apr 03, 2012 at 04:46 PM · animation

Animation Editor - 'Relative' animation positions

Hi there, I'm using the animation editor in Unity to create a quick prototype. All is well, except I need to translate the object that is animated in code. When I do this,and play the animation I recorded, it reverts back to the absolute position set in the animation editor (so for example if the first keyframe in the animation is at Y position 0, but I translate the object to 100, when I play the animation it snaps the object back to 0).

There must be a way around this I'm missing - can anyone help? Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
15

Answer by Adamcbrz · Apr 08, 2012 at 02:07 AM

Yeah this is an annoying aspect of unity animations. The easiest method is to create a parent gameobject that you position. Then the animation will play relative to that gameobject.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AntLewis · Apr 08, 2012 at 05:15 PM 0
Share

Ah great - I've tried that and it works - thanks

avatar image CarterG81 · Aug 19, 2016 at 07:02 PM 0
Share

Thanks. This method works really well, even when I have to end up creating two empty gameobjects, ending up with $$anonymous$$ainObject--->EmptyChild--->EmptyChild--->ChildGraphics

avatar image psychogeist · Jan 27, 2018 at 06:51 PM 0
Share

For anyone reading this, Unity 5+ now includes functionality to do this without using an empty gameobject or needing to resort to script:

https://gamedev.stackexchange.com/a/111368

avatar image
9

Answer by Democide · Jun 26, 2014 at 03:19 PM

Another way to handle this, which works well if your objects don't move, is to save the position of the object before you start the animation.

Like so:

     startPosition = transform.localPosition;
     animation.Play("testAnim");

Then during LateUpdate, you jus add that position on top of the position of your object, which effectively shifts it by it's original position. Since htis happens in LateUpdate it happens AFTER the animation offset was applied, maintaining the animation.

Like this:

 void LateUpdate() {
     transform.localPosition += startPosition;
 }

Since this offset is static this only works with non-moving objects. Of course you could modify this startPosition to move the object but it get's a bit more roundabout then.

Hope this helps :)

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Jun 26, 2014 at 03:21 PM 0
Share

Chill $$anonymous$$artin, sometimes it takes a little while for a moderator to get to the queue! But don't worry, it only takes 15 $$anonymous$$arma to avoid it.

avatar image Democide · Jun 27, 2014 at 08:07 AM 0
Share

Hm. Sorry, I don't quite get it.

avatar image Noukta · Apr 18, 2018 at 04:27 PM 0
Share

Thank you. This is better than using a parent gameobject.

avatar image ppartida · Apr 17, 2020 at 08:14 AM 0
Share

This worked for me as still is a problem in 2020, I used a Trigger ins$$anonymous$$d of the Play, works like a charm, thank you!

avatar image
0

Answer by Knskan3 · Sep 04, 2014 at 07:40 PM

How I solved this problem:

http://answers.unity3d.com/questions/784567/how-to-make-animation-position-start-from-last-pos.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can the animation editor create local rotational data? 3 Answers

Adding animation clips via script 2 Answers

Can I make animations snap to a frame? 1 Answer

How to select an animation clip by index number? 7 Answers

Will caching strings improve performance for animation? (and other string calls) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges