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 /
This question was closed May 16, 2016 at 12:30 PM by ZTheDragonZ for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by ZTheDragonZ · May 16, 2016 at 05:44 AM · c#animationscript.

Animation and Position

I set a game object to play an animation to change it's position and rotation and when it reach the end an event trigger start and smooth damp the object so it positioned in front of the main camera but it wouldn't do that it wouldn't move at all

  public void ChangePostion ()
         {
             Camera.main.transform.LookAt (gameObject.transform);
             Vector3 targetPosition = ItemViewer.localPosition;
                 transform.position = Vector3.SmoothDamp (transform.position, targetPosition, ref velocity, smoothTime * Time.deltaTime);
         }
 

alt text

screenshot-61.png (26.1 kB)
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

  • Sort: 
avatar image
1
Best Answer

Answer by chalkesonali · May 16, 2016 at 01:48 PM

smoothdamping is a gradual movement so it needs to be called in update function also your position is already controlled by animation curves so after completing animation you need to specify that the movement is now controlled by code and not by animation,you can do this by checking "apply root motion" on animator component.

change your code like this:

 bool canmove;
 
 void Update()
     {
          if(canmove)
         transform.position = Vector3.SmoothDamp (transform.position, targetPosition, ref velocity, smoothTime * Time.deltaTime);
     }
 
 public void ChangePostion ()
          {
          GetComponent<Animator>().applyRootMotion = true;
              Camera.main.transform.LookAt (gameObject.transform);
              Vector3 targetPosition = ItemViewer.localPosition;
          canmove=true;
          }
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 ZTheDragonZ · May 16, 2016 at 06:27 PM 0
Share

Thank you for your reply it worked like a charm

avatar image
1

Answer by incorrect · May 16, 2016 at 10:47 AM

It may be because Animator overrides it's position change. Try switching it off once your object starts being moved my trigger.

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 ZTheDragonZ · May 16, 2016 at 12:30 PM 0
Share

Thank you it worked I just make it disable the animator before making it move :)

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 script 1 Answer

How to check if Animator is playing 3 Answers

How to change the color of a UI cross hair using Raycasts 1 Answer

How can i use the Animator in script to find when animation clip finished playing and then stopping the animation ? 1 Answer

Play Animation several times 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