• 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 dylan56477 · Dec 29, 2011 at 11:02 PM · animation

How to make a shell release

So the question says it all. I wanna make a shell release for my gun and I have no problem Instantiating it through my script but it's the adding force or through an animation (which I have). Which is better? and and how would I do it? Thanks in advance!

This is the script I have so far:

 var emptyShell : Transform;
 var shellAudio : AudioClip;
 
 
 function Update () 
 {
     if(Input.GetButtonDown("Fire1"))
     {
         var bullet = Instantiate(emptyShell, transform.Find("shellReleasePoint").transform.position, Quaternion.identity);
          animation.Play("Shell Release");
     }
 }
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
0

Answer by Julien-Lynge · Dec 30, 2011 at 12:34 AM

Having never fired a gun, let me try to put this in game development terms:

You want to instantiate a gameObject and through physics, and animation, or some other means, give the gameObject velocity or a path such that it falls from its origin in a realistic way.

The dirt-simple way to do this, assuming you have colliders on all the floors and walls, is definitely to use physics. Rather than instantiating a transform (I'm surprised that even works - it's probably implicitly converting to a gameObject behind the scenes), you should be instantiating a prefab (gameObject). Make sure this prefab has a rigidbody with all the parameters you want. Then, when the prefab is instantiated, give it an initial velocity with myPrefab.transform.velocity = someValue. You can even use Unity's Random function to give it some randomness in the direction it falls. Make sure you have 'use gravity' turned on, and let Unity calculate the physics. Also make sure that the prefab has an internal script that Destroy()s itself after some set amount of time, or you'll start to seriously affect game performance as you have more and more physics objects in scene.

However, a word of caution with Physics: the physics engine has issues with small objects moving quickly. There are numerous posts that discuss what settings to tweak if you have issues, and you should definitely check out the physics documentation on the Unity website.

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.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

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

Need help with script 1 Answer

When pressing a key, play an animation, when pressing same key, play different animation? 1 Answer

Update iTween Path at Runtime 1 Answer

Animation within Unity 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