• 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 pepefirst · Mar 23, 2011 at 08:44 PM · animationthrowing

Animating and throwing and object at the same time

Nothing is simple in here.

Developing my game I need that an Enemy throws objects every 10 seconds, for instance, against my Player. Just at the same times the Enemy should mimic with an animation clip (1 second long) the repetitive throws. I have done it all, except the script piece that could allow me make the task. I wrote a very simple line script nested in my Up Date function:

animation["Take 001"].speed = 2.0;

where "Take 001" is my animation clip and 2.0 is the speed of the animation.

This made the job, but ONLY ON THE FIRST TROW. From there on only the objects are thrown but without the animations.

Any help on this LITTLE issue! (nothing is little in this field)

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 Statement · Mar 24, 2011 at 07:28 PM 0
Share

Could you post some more code?

3 Replies

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

Answer by pepefirst · Mar 27, 2011 at 02:13 AM

Here is how I resolved my problem. My animation was done in Maya, therefore I made in Maya a new animation (as my animation is very simple I only invested on it five to ten minutes) with 1 second duration and 9 seconds without movement in order to fill the 10 seconds I needed. For this I compared time an frame-times with the Unity Animator (Window > Animation, with the Character selected). I imported again to Unity the Character with the new timing and wrote the line: animation.Play("Take 001"); nested in the Up Date function in the Character script and I got the animation that I wanted synchronized with the objects launched. I am sure there are many other ways to fix the problem, but this worked very good for me.

By the way, the imported animations from Maya, at least on my case, are not editable because they produce the message Read Only in the Unity Animator.

SOLVED!

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

Answer by Meltdown · Mar 24, 2011 at 07:39 PM

Add the line

animation.Play("Take 001");

to your code that throws the objects.

If that doesn't help post us some more code and we can take a better look.

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

Answer by efge · Mar 24, 2011 at 07:41 PM

You could check the Wrap Mode (and set it to "loop"):

animation.wrapMode = WrapMode.Loop;
Comment
Add comment · Show 5 · 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 pepefirst · Mar 25, 2011 at 12:14 AM 0
Share

$$anonymous$$eltdown and efge: Thanks for your interest in my problem. To put my problem clearer: I have an Enemy who throws objects against my Player every 10 seconds; I made the script for this and it works just fine. I want to mimic the throws with an Enemy loop animation (1 second long) where he moves his right arm simulating the throwing every 10 seconds. I made also the animation and it looks good. $$anonymous$$y problem is synchronize the objects throws and the animation every 10 seconds.The Wrap$$anonymous$$ode instruction makes play the animation continuously and the animation.Play makes one single loop when game starts

avatar image pepefirst · Mar 25, 2011 at 12:16 AM 0
Share

Therefore, none of them is the solution. I would appreciate any further advice.

avatar image pepefirst · Mar 25, 2011 at 12:38 AM 0
Share

Summarizing, what I want is one animation loop every 10 seconds.

avatar image efge · Mar 25, 2011 at 07:39 AM 0
Share

Take a look at InvokeRepeating http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$onoBehaviour.InvokeRepeating.html

avatar image pepefirst · Mar 25, 2011 at 11:29 PM 0
Share

I wrote down this line: InvokeRepeating (animation["Take 001"], 0, 10);

but I got this error: Assets/Scripts/$$anonymous$$onkeyAnimation.js(20,17): BCE0017: The best overload for the method 'UnityEngine.$$anonymous$$onoBehaviour.InvokeRepeating(String, float, float)' is not compatible with the argument list '(UnityEngine.AnimationState, int, int)'. Any further advice, please?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Can the animation editor create local rotational data? 3 Answers

Adding animation clips via script 2 Answers

Can I make animations snap to a frame? 1 Answer

How to select an animation clip by index number? 7 Answers

My animation is out of sync 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