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 Martin 3 · Oct 18, 2010 at 08:07 PM · animationshooting

Bullet shooting animation

I have a character, that have a "shoot" animation. The animation take some time, because the character have to aim first, and it "shoots" almost at the end of the animation. I want the bullet to be created at a special frame of the animation, so I have made this script, but it dont work

var bullet : Transform; var newBullet; var bullets : int; bullets = 30;

function FixedUpdate() {

if(Input.GetButtonDown("Fire1") && bullets > 0 && !animation.IsPlaying("walk")) {

animation.Stop("stand"); animation.CrossFade("shoot");

}

if(animation["shoot"].time == 86) { newBullet = Instantiate(bullet, GameObject.Find("Ref_Weapon").transform.position,transform.rotation); newBullet.rigidbody.AddForce(transform.forward * 20000); bullets--; print("if Done"); } }

Why is this not working? Is there something wrong with animation["shoot"].time == 86 ?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by skovacs1 · Oct 18, 2010 at 08:53 PM

There are a couple of things that could be wrong. The simplest answer is that your FixedUpdate() is never called exactly when your animationState's time is equal to 86 seconds. Also, depending on your wrapmode, this could also make this only happen once. To fix this, you can check when the time is greater than 86 or something like that and/or changing your update step to make certain that FixedUpdate is called at the intervals you expect and/or using Update in stead of FixedUpdate.

This isn't really the best way to trigger this. You should look into AnimationEvents they are designed for exactly what you're describing, but note that you cannot modify animations that have been imported with a character, etc. For imported animations you can a) duplicate the animations and modify the duplicates (see this question) or b) create a separate animations (with your events) that you trigger to run at the same time on a separate layer. Option a) is the most practiced because option b) is not very extensible.

Comment
Add comment · Show 4 · 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 Martin 3 · Oct 19, 2010 at 01:22 PM 0
Share

Hi. I'm new to this animation event stuff, and now I have read a little about it, and it looks smart. The problem is that the animations in animation event are read-only. What to do to avoid it? I cant mess around with the model, because its not made by me, and I cant work in 3d model programs.

avatar image skovacs1 · Oct 19, 2010 at 06:32 PM 0
Share

There are a few ways to do this, but the thing to note is that you cannot modify imported animations directly. I will add information to this answer.

avatar image Martin 3 · Oct 20, 2010 at 09:00 AM 0
Share

Hi again. I have some trouble understanding whats going on in the answer in the link you sent me. In the answer, he tells me what to do with steps, and gives me a piece of code. He tells me to put something in a editor folder, but what "editor" folder and what to put in the folder?? He also assumes that you already have made a copy of the animation, but how can I do that?

avatar image skovacs1 · Oct 20, 2010 at 02:16 PM 0
Share

If you don't have an Editor folder in your project asset root, create one. You put the script in the folder - it's an editor script after all. The duplicate would just be a new animation clip on the gameobject named the_same_name_copy. You would then select the original animation clip in your project folder (should be stored in your root if you set your importer up that way) go to "Assets/Transfer Clip Curves to Copy" (that you just added with the script) and your clip has been duplicated.

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

No one has followed this question yet.

Related Questions

Wait for reload to finish? 1 Answer

repeating a shooting animation 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Play animation once 1 Answer

How can I make that two events starts when something else happens? 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