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 Liv3rbird · Jan 08, 2014 at 03:09 PM · shootingprojectile

Projectile Shooting Problem

I am using unity to create a penalty shoot-out game. I also have a power bar in the scene. Now when I click to shoot the ball, the first time , two balls are going off simultaneously . I would like only one ball to be shot . Thanks , and here is my script;

 #pragma strict
 
 // maximum width of the powerbar 
 var fullWidth : float = 256;
  
 //create a boolean flag we can use to stop and start the choosing of power
 var choosing : boolean = false;
  
 //create a private variable (not shown in inspector) to store the current set power
 private var thePower : float;
  
 //create a slot to assign my ball prefab to.
 var ball : Rigidbody;
  
 //create a slot to assign an empty game object as the point to spawn from
 var spawnPos : Transform;
 var staffingSpeed ;
  
 // create a number to multiply the force by as the value of up to 256 may not be enough to
 // effectively shoot a ball forward
 var shotForce : float = 5;
  
 function Update () {
  
  
  // detect if key is released and then call the Shoot function, passing the current
  // value of 'thePower' variable into it's 'power' argument
  if(Input.GetButtonUp("Jump")){
   Shoot(thePower);
  }
  
  if(!choosing){
   //create a power variable and set it to ping pong function
   //from current time to 1, and multiply that by a number (or variable holding a number)
   thePower = Mathf.PingPong(Time.time, 1) * fullWidth;
  
   //set the width of the GUI Texture equal to that power value
   guiTexture.pixelInset.width = thePower;
  }
 }
  
 // start the 'Shoot' custom function, establish a
 // float variable to be fed with a number when function is called
 function Shoot(power : float){
  
  
  //create a ball, assign the newly created ball to a var called pFab
  var pFab : Rigidbody = Instantiate(ball, spawnPos.position, spawnPos.rotation);
  
  //find the forward direction of the object assigned to the spawnPos variable
  var fwd : Vector3 = spawnPos.forward;
  pFab.AddForce(fwd * power*shotForce);
  
  //pause before resuming the power bar motion
  yield WaitForSeconds(2);
  
  
 }
Comment
Add comment · Show 1
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 semiessessi · Jan 09, 2014 at 04:38 PM 0
Share

What is yield WaitForSeconds 2 doing there?

WaitForSeconds is exceptionally poorly named and part of a poorly thought out set of 'coroutine' features. Its very likely you are using it incorrectly.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Inkinsarto · Jan 08, 2014 at 03:30 PM

Check and make sure you do not already have a ball, in the scene before you run the game.

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 Liv3rbird · Jan 08, 2014 at 03:37 PM 0
Share

I have one ball , and one empty game object so that the ball will re spawn there. Is that good?

avatar image Inkinsarto · Jan 09, 2014 at 04:28 PM 0
Share

Being that a ball is there before the game runs, it will act with similar properties to a regular ball when fired. $$anonymous$$ake the ball a prefab, (if not already) then delete it in the scene view. Just don't mess with the empty game object for spawning.

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

20 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

Related Questions

A node in a childnode? 1 Answer

How to make projectiles shoot diagonally? 1 Answer

Unity Messing up Basic Math? Projectile Trajectory Algorythm 1 Answer

Projectile Y-axis start position issue - 2.5D Platform 0 Answers

Destroy method returning null. 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