• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by IKilledKenny_2 · Dec 09, 2014 at 01:35 AM · throwing

Throw Object

Hello Unity3D i have a Question about objects.How can i throw a prefab object?For Example.Whenever i throw a particle prefab it throws just fine.But whenever i throw a ball or a stick the prefab appears but it goes nowhere.Why is it that i can only throw a prefab particle and not a prefab game-object?If anyone knows how i can throw a prefab game-object.Can you please tell me how?

Heres The Script If anyone Needs it

 var rocket : GameObject;  //our prefab
 var throwPower : float = 10; //power variable determines how fast this object will be "shot out"variable 
 var reloadTime = 10; //time to reload
 var timeBetweenShots = 10.0;
 private var nextFire : float =0.0;
 private var timestamp = -10.0;
 function Update ()
 
 {
 if (Input.GetKeyDown("1")&& Time.time > nextFire) {
          if (Time.time > timestamp + timeBetweenShots ) {
               Debug.Log("I'm firing now");
               timestamp = Time.time;
 
 
 Switch();
 
         }
     }   
 }    
 
 function Switch()
 {
     yield WaitForSeconds(1);
 
 
 
  
 clone = Instantiate(rocket, transform.position, transform.rotation); //the clone variable holds our instantiate action
  
 clone.velocity = transform.TransformDirection(Vector3.forward * throwPower); //applies force to our prefab using the "forward" position times our throwPower variable
 
 
  
 }
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

2 Replies

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

Answer by cariaga · Dec 09, 2014 at 08:32 AM

replace

clone.velocity = transform.TransformDirection(Vector3.forward * throwPower);

with

 clone.AddForce(Vector3.forward* 500); //Moving projectile

make sure your clone has a rigidbody

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 IKilledKenny_2 · Dec 10, 2014 at 04:12 PM 1
Share

Thank You So $$anonymous$$uch!.The only thing is that i got to change the 500 into 10000 in order for it to move faster(if anyone else was planning of using this code as well..)

avatar image
0

Answer by makaka-org · Jun 19, 2018 at 12:00 PM

Hey, Guys!
Check my asset called Throw Control (documentation).

Throw Object — Unity Asset Throw Object — Unity Asset


-1.jpg (195.0 kB)
3.jpg (229.7 kB)
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

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

Related Questions

A node in a childnode? 1 Answer

Can't find my messages 1 Answer

Disable a GameObjects scripts knowing only the GameObjects name 3 Answers

rotating at mouse 0 Answers

Coroutine to WaitForSeconds() on enemy AI causing all instances of AI to pause. Solution? 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