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 Julian_Spring · Mar 20, 2013 at 07:09 PM · randomthrow

Throwing Objects

Ok so I want to throw objects randomly on a board - So they all land in random places.

I have attempted a script but it is a little to embarrassing as I'm not the best programmer yet.

Any help will be very helpful. Just looking for a starting script that I can play with.

Thanks

 var projectile : Transform;
 var projectile2 : Transform;
  
 function Update () {
   
     if (Input.GetButtonDown("Fire1")) {
  
     // Instantiate the projectile at the position and rotation of this transform
     var clone : Transform;
     var clone2 : Transform;
     var clone3 : Transform;
     clone = Instantiate(projectile, transform.position, transform.rotation);
     clone2 = Instantiate(projectile2, transform.position, transform.rotation);
    
  
     // Add force to the cloned object in the object's forward direction
     clone.rigidbody.AddForce(clone.transform.forward * 400);
     clone2.rigidbody.AddForce(clone.transform.forward * 400);
    
     
     }
 }
Comment
Add comment · Show 2
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 robertbu · Mar 20, 2013 at 07:14 PM 0
Share

Even "embarrassing" code is often gets you better answers than no code because it educates the person attempting to answer your question about what you are trying to do. "Throw" can mean several things depending on how you are moving your objects for example. If you were simply translating them the answer would be different than if you are using a Rigidbody and adding force.

avatar image AlucardJay · Mar 21, 2013 at 05:03 AM 0
Share

robertblu and Julien.Lynge are absolutely correct. Refer to this video : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers

I keep having these mood swings, currently my mood is set to 'mercy'. Search Unity Gravity Gun : http://lmgtfy.com/?q=Unity+Gravity+Gun

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Julien-Lynge · Mar 20, 2013 at 07:15 PM

@Julian_Spring,

Your post (as it appears now) isn't something we can give you a quick answer for, and isn't really appropriate for UnityAnswers. The UnityAnswers philosophy is:

"[Unity Answers] is a place to ask specific questions that have specific answers. The forum is a better place to post discussions and non-technical questions."

It sounds like what you're looking for is Unity training, rather than a specific answer. I would suggest visiting the following training websites to find the one that best helps you move forward. In addition to the sites below, you can always search YouTube, which has a large number of user-created Unity tutorials.

  • 3DBuzz (hover over the Unity dropdown) - http://www.3dbuzz.com/vbforum/sv_home.php

  • Lynda - https://www.lynda.com/

  • BurgZergArcade - http://www.burgzergarcade.com/

  • Unity3DStudent - http://www.unity3dstudent.com/

  • UnityGems - http://unitygems.com/

  • CGCookie - http://cgcookie.com/unity/

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 Finn_C · Aug 13, 2021 at 02:08 AM

There is absolutely no way you're still working on the same issue, but this is for anyone who needs to see this. You could try adding a force to the rigidbody component of whatever object you want to be thrown. For example, if a certain button is pressed, a force would be added to the rigidbody causing it to move forward. using UnityEngine;

 public class ThrowingObject : MonoBehaviour {
 
     public Rigidbody rigidBody;
     public float forwardForce = 2000f;
 
     void FixedUpdate ()
     {
         if (Input.GetKey("Fire1"))
         {
             rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0);
         }
     }
 }

This could work.

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.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

Throwing random projectiles in a parabolic trajectory 0 Answers

How to move object at random direction,that changes after some amount of time? 2 Answers

Randomly spawn a trigger area 1 Answer

Help with Generating Random Tiles 1 Answer

Random time interval 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