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 decoy98 · Jan 16, 2014 at 10:59 AM · instantiateshootingbullet2d physics

Very basic Instantiate Question

Here is my super simple game: https://dl.dropboxusercontent.com/u/33685163/testUnity/testUnity.html

Here is my movement code: http://pastebin.com/HXHTLXyU

My question is how do you make it so that the bullet fires slowly in the direction it's currently facing just like the way tanks shoot in this video: http://www.youtube.com/watch?v=VM6iZgSaeX0

I also want to be able to show the game cursor while playing but when I upload the build the cursor disappears, though I can see it while being in play mode.

The games controls are: mouse click to move the player, and space bar to shoot the bullet.

Thank you very much, I really appreciate all the help from pros like you!

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 Dugular7 · Jan 16, 2014 at 12:24 PM 1
Share

Hey there. You may get a few more responses if you post your code in the actual question rather than link to it :) People are sometimes hesistant to click away from the site.

avatar image Sir-Irk · Jan 16, 2014 at 04:15 PM 0
Share

Have you tried using cloneBullet.addForce(Vector2 force)? For example cloneBullet.addForce(transform.forward * 10f);

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Wiki

Answer by ozku · Jan 16, 2014 at 01:05 PM

moveDirection = transform.TransformDirection(Vector2.right); That should work but I'm not 100% sure because I only know javascript...

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 Sir-Irk · Jan 16, 2014 at 01:05 PM

You want to create a float variable to keep track of how much time has passed since your last shot. In your update do something like this

 float timeElapsed = 0.0f;
 
 void Update(){
     timeElapsed += Time.deltaTime;
 } 

Then in your shooting code check if timeElapsed is >= your firingRate and reset timeElapsed to 0 every time you successfully shoot a bullet. For example setting firingRate to 0.25f would allow a shot every 250 milliseconds.

Edit1: Also, you can use transform.forward to get the current object's forward direction.

I'd personally recommend moving your shooting code to a separate script though. This makes debugging and modification easier.

Edit2: Another tip: you can make a new gameObject with a transform component and make it a child of your player. You can then put your shooting script(should be seperate form the movement script) on this new transfrom object and adjust it's transform.localPostion. This allows you to easily change the position of where your bullets come from. Just make sure that this child object's rotation is set so that it's forward direction is the same as the parent's forward direction.

I'm not sure about the cursor issue. Do you have any scripts that turn the cursor on or off and/or locks the cursor? Check your player settings for your build and see if there is anything that needs to be changed.

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

21 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

Related Questions

need help with instantiating for making a bullet shoot 1 Answer

Bullet stops when new bullet instantiates pls help 3 Answers

Control amount of bullets 2 Answers

Invoke is not working properly. 0 Answers

Enemy Damage problem 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