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
0
Question by $$anonymous$$ · Nov 05, 2012 at 03:54 PM · animationcamera

Set animation end position as new position

I have a camera and when I press a button the camera plays an animation. After that the player can push again on a button and the camera should play another animation but from where the camera is located at that point. And not from where it was before the first animation.

So what I though I could do is:

 1. Play the animation
 2. wait till the end
 3. Get the position and rotation
 4. Stop Animation
 5. Rewind animation to start frame
 6. Set new position and rotation

If I Rewind and Stop that animation stays at its last frame instead of going back. And if I wait for next fixed update the camera is at the first frame of the animation. And if I then put the camera to its previous rotation and position, it works but you see it go back to the first frame and then back to new position. So you see the screen change twice.

Here is what I had:

     protected override IEnumerator CameraAnim()
     {
         Camera.main.animation.Play(CameraAnimation.name);
 
         yield return new WaitForSeconds(CameraAnimation.length);
 
         Vector3 pos = Camera.main.transform.localPosition;
         Quaternion rot = Camera.main.transform.rotation;
 
         Debug.Log(pos);
 
         Camera.main.animation.Rewind(CameraAnimation.name);    
         Camera.main.animation.Stop(CameraAnimation.name);
 
         Camera.main.transform.localPosition = pos;
         Camera.main.transform.rotation = rot;
 
         Debug.Log(pos);
 
         IsActive = true;
     }
Comment
Add comment · Show 1
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 $$anonymous$$ · Nov 06, 2012 at 08:37 AM 0
Share

I have updated the question, figured out why camera position was not updating. Any ideas on the animation?

1 Reply

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

Answer by Paulius-Liekis · Nov 06, 2012 at 09:39 AM

There are multiple ways to do it, but here are some pointers:

  • Set animation wrapModel to Clamp, this way you'll be sure that your animation doesn't jump back to the start when it's over. Then simply do Rewind as you do now.

  • Calling Rewind, Stop, changing time on AnimationState, doesn't change transforms immediately. Most people use MonoBehaviour.Update to Stop/Play/etc animation and then get position of transforms in MonoBehaviour.LateUpdate, because that's where animation animation is sample with latest state. Anyway, you can get it working with coroutines, read on...

  • If you want to get transfroms to be update on the same frame, then simply call Animation.Sample and it will force-sample the animation.

  • Also calling Rewing and Stop resets animation to start and stops playing it, so your AnimationState.time is 0, but it doesn't get resampled because you called Stop and this way stopped playback of the animation. Soliution: call: Rewind; Sample; Stop. This way it will rewind animation, resample it and then stop it.

If you want to have better undestanding about Unity-update-loop, read this: http://docs.unity3d.com/Documentation/Manual/ExecutionOrder.html (especially: "So in conclusion, this is the execution order for any given script:" part)

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 $$anonymous$$ · Nov 06, 2012 at 10:15 AM 0
Share

That is a very interesting document :). Thanks, now I don't have to wait till next frame.

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

10 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

Related Questions

How to animate camera effects (legacy)? 0 Answers

Disabling Camera's "Mouse Look" while camera animation playing 0 Answers

Como activar una animacion al hacer clic en un objeto (How to activate an animation when you click on an object) 1 Answer

Make the player go into the direction I am looking at 0 Answers

Controlling a character - Character is not moving. 0 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