Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
1
Question by matta9001 · Jul 15, 2015 at 01:25 AM · c#animationtransform

Having an animation enabled locks transform changed in the animation

I have an object, that i rotate through a script. And i have an animation, that also rotates this object. But when i make the animation, even if the script is not going it prevents the script from rotating this object. How do i make it so that when the animation is NOT playing it allows the script to rotate the object.

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

Answer by SomeGuy22 · Jul 15, 2015 at 01:44 AM

I'm a little confused, do you want to check if the Animation is not playing? To do so, you must check the parameters you plug into Mecanim (assuming you're not using Legacy animation). For example if you rotate the object based off "parameter Rotate > 5" then just check if that parameter is not greater than 5.

However, I think what you really want is to override the rotation of the animation and rotate from the script instead. To do so, simply call your rotate function in LateUpdate() instead of Fixed or regular Update(). LateUpdate() is called after Update(), where all animation happens.

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 matta9001 · Jul 15, 2015 at 01:53 AM 0
Share

I don't want to check if an animation is not playing. I'm saying regardless of if its playing or not, the parameters that are changed during the animation are locked while the animation is not playing. So for example, i change the rotation in the animation. But, when the animation is NOT playing, the rotation is still locked, even if i try to change it in the inspector, the animation prevents me from changing it. However if i remove the animation from the scene completely it works.

avatar image matta9001 · Jul 15, 2015 at 02:15 AM 0
Share

and doing it in LateUpdate() doesn't work for whatever reason, the animation seems to be disabling all rotation at all from any place.

avatar image barbe63 · Jul 15, 2015 at 08:52 AM 0
Share

Disable the animator when you need to transform yourself. At least that's what I do.

avatar image
1

Answer by MadJlzz · Sep 30, 2015 at 07:10 PM

Just set applyRootMotion = true; when you don't need the animation to take on your own movement.

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 shivansh11 · Jul 27, 2018 at 02:14 PM 0
Share

Thanks! That helped me! :D

avatar image
0

Answer by GoblinGameWorks · Oct 14, 2019 at 02:52 AM

@matta9001 .

Ok, I know this is an old post but I had a similar issue in 2019. I am making a rails shooter type game (think starfox 64) and I needed the enemies to be on their own timeline or rail animation (Which moves their physical position in the scene but also locks their rotation to whatever rotation is recorded in the animation) while still being able to move the enemie's game object's local rotation to face the player so they could shoot at him randomly.

After several hours of research, I got it. - this post being the most relevant:

this bit of code I got from another topic in these forums, and it makes the enemy face the player:

public class LookAtPlayer : MonoBehaviour { [SerializeField] Transform target;

 void Update()
 {
     if (target != null)
     {
      transform.LookAt(target);
     }
 }

}

But this is not enough in my situation since the rotation of the enemy is locked by the animation of the rail. Then I found this:

https://docs.unity3d.com/Manual/class-RotationConstraint.html

A rotation constraints component that you can add to a game object. It allows you to constrain the object's rotation to a rotation of your choosing OR to mimic the rotation of another game object that you set under "sources". So:

Step 1 - put all the enemies you want to behave this way under a parent empty game object (name it anything that fits what your working on).

Step 2 - make an additional child to this parent object and call it "Look At Player" (name optional) make sure the transform of the "Look At Player" game object is close to the enemies or enemy that you are trying to control. (so it faces the right way)

Step 3 - Make a script with the LookAtPlayer code I showed above and save it.

Step 4 - Attach the LookAtPlayer script to the LookAtPlayer game object and drag your player's prefab into the "target" field of the LookAtPlayer script.

Step 5 - add a rotation constraints component to all the enemies you want to control this way, click the "Zero" button, add a source to the source list and drag the LookAtPlayer game object to make it the source of the enemies rotation.

You are done, the result should be: - your animation plays like you wanted it to - your enemy is mimicking the rotation of the LookAtPlayer game game object (which is not restricte by an animation) - the LookAtPlayer game object has a script that always looks at the player. - Thus your enemies now will always look at the player.

Sort of a "monkey see monkey do" result. Don't know if this is an answer or a work-around but it works. Hope this helps others with similar situations.

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

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

Related Questions

transform.position not setting position OR animation setting position even though it shouldn't 0 Answers

How do i rotate an object "Once" 1 Answer

Distribute terrain in zones 3 Answers

"Lerp" back to original position after animation. 0 Answers

Multiple Cars not working 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