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
2
Question by Erwin_Br · Jan 26, 2011 at 08:38 PM · animationparent

Animation does not play in relative position, even with parenting

I created a simple bounce animation using Unity's animation editor. I learned that you have to create an empty game object as a container/parent if you want the animation to play at the current position of the object, so I did and put the player object inside this empty game object. Then I created the animation on the player object itself.

A script, also on the player object (not the empty game object!), triggers the animation when you reach a certain coordinate.

To my frustration, when I play the animation, it plays it at the original coordinates of the player object, and NOT at the location it currently is at.

Have I forgot something else? Am I missing something?

To recap: I have an empty game object as a parent. The animation (and scripts, rigid body, collider, etc...) are all located on the player object INSIDE the empty game object.

Help would be much appreciated. Thanks.

Comment
Add comment · Show 2
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 DaveA · Jan 26, 2011 at 11:04 PM 0
Share

Can you post any code or screenshots?

avatar image Erwin_Br · Jan 27, 2011 at 12:26 AM 0
Share

Sure. Below you'll find a screenshot of how I setup the game object:

http://www.emptyhouse.net/fileshuttle/snapshot_1dec.jpg

The code is a simple currentTransform.animation.Play("BounceTest");, and works fine, except the game object plays it at the default 0,0,0 location, ins$$anonymous$$d of the current location.

5 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Erwin_Br · Jan 27, 2011 at 09:45 PM

Okay, after struggling for another day I seem to have found the solution.

The solution is that I need to animate the empty PARENT object, the container, and NOT the game object inside it! Since my script is still attached to the object inside the empty parent, I need to call the animation on the parent like this:

currentTransform.parent.animation.Play("BounceTest4");

I don't think I have ever seen this in a tutorial, but apparently it works. I wish the documentation would be more clear about this, because the bald patch on my head is definitely growing.

Comment
Add comment · Show 2 · 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 Lomo_Unity · May 06, 2013 at 04:23 AM 0
Share

I don't understand with this section. I also have with this problem.

avatar image A-man tuna · Mar 17, 2014 at 07:55 AM 0
Share

when i type in currentTransform i get a compiler error saying unknown identifier 'currentTransform.'

avatar image
0

Answer by DaveA · Jan 27, 2011 at 01:40 AM

I'm guessing: The original animation was in world space. When you parented it, it offset that to appear in the same place, offset from the parent. Check the values on your animation curve(s) they may be quite different from what you originally authored.

Comment
Add comment · Show 1 · 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 Erwin_Br · Jan 27, 2011 at 11:46 AM 0
Share

I was pretty sure the animation was created in local space. To be sure, I created a new one in local space. It still plays at the original location. Another screenshot, showing the animation: http://www.emptyhouse.net/fileshuttle/snapshot02_8b03.jpg

avatar image
0

Answer by Bomadeno · Aug 29, 2012 at 02:03 PM

In addition to the previous answers, make sure root transform has no animation curves. If it does, it will play in world space.

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
avatar image
0

Answer by gringofxs · Jul 13, 2013 at 04:25 PM

do you have the complete script sentence.

currentTransform.parent.animation.Play("BounceTest4");

Comment
Add comment · Show 1 · 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 Shinugami · Feb 14, 2014 at 01:05 PM 0
Share

I have the same problem. I want a turret's barrel to recoil when shot however if the turret aims up, ins$$anonymous$$d of recoiling back into the base of the turret (as expected) the barrel slides on the world Z axis ins$$anonymous$$d of local z axis and results in a retarded turret. Tried putting that animation component on all objects above and including the barrel and the result is the same.

avatar image
0

Answer by jveronda · Mar 03, 2014 at 04:59 AM

im having the same problem with just getting an enemy to have a walking animation when it comes towards me. any help??

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

8 People are following this question.

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

Related Questions

Use Parent to fix the rotation of character 1 Answer

Making an animated door, that will be reused over a level, need to reference its parent 2 Answers

what to do the parents animation doesnt play on child gameobject in unity 5.6? 1 Answer

Attaching First Person Controller to Kinematic Rigidbody 1 Answer

RE: Archer FPS script 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