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 dabvid · Oct 28, 2014 at 06:09 PM · animation2drotation2d rotation

Animation in Unity editor prevents rotation in script

What I'm trying to do

A 2D character with a bazooka attached. Character can move only left and right on the floor. When pressing up or down the bazooka will rotate, kind of like the bazooka in "Worms".

I animate the body parts of the game character when the he walks and would also like to animate the bazooka to move a little when the character is walking. I would prefer to do this visually with a key frame animation, not in code.

My problem

The code for rotating the bazooka works perfectly until I created a key frame animation involving the same bazooka. To confirm I then removed the GameObject from the key frame animation and the rotation starts working again.

Just to be clear, the animation is not running and is not suppose to be running the same time as the rotation is occurring.

Basically it seems I have to choose between the keyframe animation of the bazooka or being able to rotate the bazooka on key up or down at all.

Is there a technique to do this "the right way", without having to make this choice?

Code used for rotation

Not sure its needed but the code below runs in FixedUpdate to rotate the weapon around it's own axis when pressing up or down.

 if (Input.GetKey ("up")) {
     weapon.transform.Rotate(Vector3.forward);
 }
 if (Input.GetKey ("down")) {
     weapon.transform.Rotate(Vector3.back);
 }
Comment
Add comment · Show 3
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 Wisearn · Oct 28, 2014 at 06:54 PM 1
Share

I don't know too much about the specific issue, but what you could do is to put the visuals and animation as a child object and then rotate the parent object, then your animations will work in local-space so it seems like he is not rotated (as he isnt, just his parent, which will change how the "world" seems to be rotated) and the animation doens't have to care.

avatar image dabvid · Oct 29, 2014 at 05:23 PM 0
Share

Thanks for the comment! Seems like a clever solution. Not sure I follow you though with adding the visuals and animation as child object. Could you please explain that a little more? I also updated my question to more clearly state my issue.

avatar image dabvid · Oct 30, 2014 at 08:24 AM 0
Share

Thanks again Wisearn. Your answer got me to the solution.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by g8minhquan · Oct 30, 2014 at 01:24 AM

Create a prefab with this kind of structure:

 ParentObject
    L AnimObject

Make your script control the parent object, while the Animation control the AnimObject

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 dabvid · Oct 30, 2014 at 08:22 AM 0
Share

Thanks! What I did exactly was creating a parent object and control its rotation with my script as you mentioned. I Do my keyframe animation on the child object containing the sprite. It works! One issue was getting the same size of the parent as the child. Solved it by assigning the parent a sprite renderer with the same sprite, then disabled that sprite renderer.

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

How to rotate an object using animation clip in opposite direction? 1 Answer

Counter is not working correctly with LeanTween 0 Answers

how to rotate 2d obj on android 1 Answer

Character still walking when no key is already pressed 1 Answer

Localscale-flipped 2D character retains original rotation since 5.4 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