Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by zachypin · Jul 12, 2011 at 08:02 PM · animationpositionanimationsloop

Why does animation clobber my positioning code?

Okay so I have two objects in my world, one with a looping animation, and one without. The below code is supposed to take the object and move it in front of my avatar. I attach the below code to both objects and the object without the looping animation does exactly what was intended. The object with the looping animation stays in some random place in the world. If I turn the animation off in the inspector the object works as it's supposed to, put it back on and the problem occurs again. Any ideas?

 var objectToFollow;
 var ufoVisible = false;
 
 function Update () 
 {
     if(gameObject.Find("localPlayer")==null)
     {}
     else
     {
         if(ufoVisible)
         {
             objectToFollow = GameObject.FindWithTag("Player").transform;
             transform.rotation = objectToFollow.rotation * Quaternion.Euler(0,-90,0);
             animation.Play("Take 001");//added
         }
         else
         {
             objectToFollow = GameObject.FindWithTag("Player").transform;
             transform.position = objectToFollow.TransformDirection(Vector3.forward * 4) + objectToFollow.position;
             transform.rotation = objectToFollow.rotation * Quaternion.Euler(0,-90,0);
             animation.Stop("Take 001");//added
         }
     }
     
     if(Input.GetKeyUp("u"))
     {
         if(ufoVisible)
         {
             ufoVisible = false;
         }
         else if(!ufoVisible)
         {
             ufoVisible = true;
         }
     }
 }
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

2 Replies

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

Answer by HolBol · Jul 12, 2011 at 08:05 PM

It's because when animating, you should always keep the model at the pivot, because the animation plays in local space with the model. You'll just have to adjust the numbers until it fits right, or reanimate.

Comment
Add comment · Show 8 · 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 zachypin · Jul 12, 2011 at 08:11 PM 0
Share

I guess I'll just change order of operations to attach, animate, loop animation.

Pretty unsatisfying answer though :(

avatar image Joshua · Jul 12, 2011 at 08:15 PM 1
Share

Well it's just something that you have to understand, animations play in local space - it'd be horrible if they didn't. ;)

avatar image HolBol · Jul 12, 2011 at 08:19 PM 1
Share

soz man, it's the only answer there is.

avatar image zachypin · Jul 12, 2011 at 08:22 PM 0
Share

problem still. I edited my code from above to reflect what I'm doing now. You can see that I now turn the animation off when the game starts. Then when I want to turn the animation on I manipulate its position first and then turn the animation on, however the position still doesn't change.

avatar image zachypin · Jul 12, 2011 at 08:31 PM 0
Share

I edited it once again and got rid of all the position code except for the initial positioning. So now when the game starts the position of the ufo is correct, right in front of my avatar. As soon as the animation starts, even though no positioning code is being hit, the ufo gets shot off into the world to some random place. -_-

Show more comments
avatar image
0

Answer by DaveA · Jul 12, 2011 at 08:33 PM

I may be way off here, but an idea: Seems that animation curves affect the transform. So does the code, but the animation is 'winning' this fight. What if you reparent the object, with the animation curves on the child, and the animation code on the parent (or vice-versa)?

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 Joshua · Jul 12, 2011 at 08:39 PM 0
Share

This would still mean that the animation's re-positioning happens after the re-positioning in the Update function, won't it? Giving LateUpdate a try could work though, perhaps. The problem is I have no idea 'when' in a frame the animation is played, I wouldn't be surprised it's saved for the end.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation precision is lost for character's blinking 1 Answer

Abaut Mecanim animation roop 0 Answers

Problems with an animation 0 Answers

Animation finish completely? 3 Answers

In animations, is it possible to only add transform values instead of setting it? 2 Answers


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