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 QuantumJon · Apr 18, 2013 at 08:51 PM · instantiatebulletshooterfireshot

Bullets won't fire?

I'm making a top-down shooter game, but I can't get the bullets to actually travel once they're shot. They simply remain at the spawn point and no more than one bullet is present at any time, from what I could tell. The code I have is:

 var bullet : Rigidbody; //Your bullet prefab. Should have a RigidBody
 var speed : float = 10.0f;
 var muzzlePoint : Transform; //Your SpawnPoint
     
 function Update() {
        if(Input.GetButtonDown("Fire1")) {
            var instance : Rigidbody = Instantiate(bullet, muzzlePoint.position,
                                                    muzzlePoint.rotation);
            instance.velocity = muzzlePoint.forward * speed;
     }
 }

The gun has an empty game object in front as the "muzzle". Is there an issue with the code? Or what do I do? Thanks in advance.

Comment
Add comment · Show 5
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 oliver-jones · Apr 18, 2013 at 10:47 PM 0
Share

What happens if you hold down your fire button?

avatar image AlucardJay · Apr 19, 2013 at 04:24 PM 0
Share

When they are spawned, are they too close to the muzzle? If your bullets are colliding with something after they are instantiated, then yes they will not move. Does your bullet have gravity enabled? I'm surprised they do not fall if they are. I also assume you tested raising the value of speed.

What happens if you hold down your fire button? : oliver, what kind of question is that? The answer is nothing, read the script :

 if(Input.GetButtonDown("Fire1")) {

GetButtonDown : http://docs.unity3d.com/Documentation/ScriptReference/Input.GetButtonDown.html

Sorry, but I really couldn't see the purpose of your comment.

avatar image QuantumJon · Apr 23, 2013 at 06:22 PM 0
Share

Sorry for the late reply. I've tried moving the bullet around away from the muzzle, but no luck, no matter what the position is. Unless they're colliding with themselves, I still haven't figured out why it isn't working. Thanks for the suggestions, though.

avatar image robertbu · Apr 23, 2013 at 06:34 PM 0
Share

I just tested your script on a new scene using an empty game object. It worked fine. So you need to step through your situation to see what is going on. Check for any errors output to the Console window. Add code to your bullet to see if it is colliding with something. Start from the $$anonymous$$imal setup I tested above and add items to build your scene. Etc.

avatar image QuantumJon · Apr 25, 2013 at 07:07 PM 0
Share

After backtracking through a lot, I've retested it and it works fine. Not sure what went wrong, but it's working now. Thanks =]

0 Replies

· Add your reply
  • Sort: 

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

Quick Bullet Instantiation Problem 2 Answers

Setting bullet instansiate direction? help? 1 Answer

shot delay in between bullets 1 Answer

Make a Gun fire multiple times 3 Answers

How can I shooting script c#? 0 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