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 antwonline · May 07, 2013 at 03:05 PM · raycastballshootshooterray cast

How do I instantiate and shoot a ball along a ray cast? [ANSWERED]

alt text

Hi Guys, Above is the GameObject that I am working on [IMAGE]. The balls fall into the catcher, and are destroyed when they hit the bottom of it (out of the players view).

My aim now is to instantiate a new ball behind the circular cannon and shoot it in the direction it is facing. (It is a separate GameObject that the user can rotate).

Any help would be greatly appreciated. Thank you!

screen shot 2013-05-07 at 11.16.22 pm.png (81.4 kB)
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
Best Answer

Answer by BlackWingsCorp · May 07, 2013 at 03:40 PM

Hey add an empty gameobject (let's call it launcher) to the scene and make it a child of the gameobject that the user can rotate and reset it's transform values. Afterwards place the launcher at the tip of the canon in a way they don't collide together. when done open monodevelop and write something like this tell me how it works :

 public Rigidbody ball;
 public float speed = 200; //change it according to the desired speed
 
 void Update(){
 if(Input.GetButtonUp("Fire1"){//if the player clicks the left mouse button then releases
 public Rigidbody newBall = Instantiate(ball, transform.position, transform.rotation);
 newBall.velocity = transform.forward * speed;
 Destroyer(); 
 }
 }
 
 void Destroyer(){
 yield new WaitForSeconds(2);//waits 2 seconds before destroying the newBall 
 Destroy(newBall.gameObject);
 }
 
 
 
 
 

 
Comment
Add comment · Show 2 · 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 antwonline · May 08, 2013 at 02:42 AM 0
Share

Thanks heaps! You're a great help. I changed a bit here and there, and this is what I ended up with.

 public var firedBall:GameObject;
 public var speed:float = 200; //change it according to the desired speed
  
 function Update(){
 ballShooter();
 }
 
 
 function ballShooter (){
 yield WaitForSeconds(2);
 if(GunBall$$anonymous$$iller.ballsReadyToBeShot>=1){
     GunBall$$anonymous$$iller.ballsReadyToBeShot-=1;
     var newObj = Instantiate(firedBall, transform.position, transform.rotation);
     Globals.activeBalls++;
     newObj.name="FiredBall";
     newObj.velocity = transform.forward * speed;
    }
 }

Thanks!

avatar image robertbu · May 08, 2013 at 02:51 AM 0
Share

If you are happy with his answer, click the checkmark next to the answer. This closes the question out and also gives karma to the person who answered your question.

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

14 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

Related Questions

Multiple Light Guns 0 Answers

iPhone touch raycasting 1 Answer

my ray cast is only shooting out a few meters no matter the distance. 1 Answer

ball sometimes goes through the bat when hit... collider problem... How to do a Raycast? 0 Answers

How to Implement First Shot Accuracy? 2 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