• 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 Mystic 2628 · Jun 02, 2014 at 09:16 PM · gun movementgun position

Bullet won't move with gun?

I've just implemented gun movement into my slowmotion bullet dodging game so that the player will be fired at from different places rather than all in the one limb. Unfortunately, the bullet that sits in the barrel of the gun won't move with the gun, even if i attach the exact same movement script to it as is on the gun itself, it'll then fly off out of the arena never to be seen again.

I'm wondering how could I constrain the bullet to the guns position without setting it as a child of the gun, as when I use the child feature the bullet seems to rotate randomly and hover above the gun as if it's speed is double the guns speed.

Is there any simple (or even complicated?) way to lock the bullets position to the gun?

Comment
Add comment · Show 4
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 Lovrenc · Jun 02, 2014 at 09:31 PM 0
Share

Why would you want a bullet in your barrel?

avatar image Mystic 2628 · Jun 03, 2014 at 08:27 AM 0
Share

Because it hides it. And also because I messed up somewhere and made it so the bullet instantiates on the bullet.

avatar image Lovrenc · Jun 03, 2014 at 07:33 PM 0
Share

If you don't want the player to see the bullet, don't even instantiate it until you need it.

avatar image Mystic 2628 · Jun 05, 2014 at 07:53 PM 0
Share

But I can't seem to instantiate it in the right spot otherwise...

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by oasisunknown · Jun 05, 2014 at 11:20 PM

I don't understand why you cant use an empty game object as your spawnPoint for the bullets. Then when you Instantiate the bullet just feed in the spawnPoints transform.

The empty game object used as the spawnPoint would not have any scripts attched and would only be parented to the gun as a transform reference so you should not have any of the excess speed movement issues you were talking about that you had for the bullets.

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 Mystic 2628 · Jun 06, 2014 at 07:50 PM 0
Share

We've got a winner. I don't know why I did this for everything else and not the bullets...

avatar image TonyTsimou · Apr 17, 2020 at 01:22 AM 0
Share

This is exactly what i've done, and through debugging the spawnPoint is where it is supposed to be - but bullets are spawning at that point. Also after debugging i found that if the spawnpoint is NOT set as a child then the spawn location is correct.

  void ShootBullet(RaycastHit hit)
     {
         GameObject bulletProjectileInstance = Instantiate(bulletProjectile, bulletProjectileStartPosition.transform.position, Quaternion.identity) as GameObject;
 
         Destroy(bulletProjectileInstance, 2f);
 
 
     }



alt text

proof.png (233.9 kB)
avatar image
0

Answer by gooncorp · Jun 02, 2014 at 10:41 PM

one way to solve it is to use a rigidbody and let the physics do the work for you. instantiate the bullet, addrelative force to it using guns trajectory etc. make sure you delete it quickly as this way can be a bit heavier.

Comment
Add comment · Show 1 · 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 Mystic 2628 · Jun 03, 2014 at 08:29 AM 0
Share

I'm still confused. I have a rigid body on the bullet already.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

25 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 avatar image avatar image avatar image avatar image

Related Questions

Time.deltaTime not working? 1 Answer

How can I make an object always look at the mouse? 2 Answers

How to make a gun work with camera? 1 Answer

How do I add rotation to movement so that a bullet does not travel in a straight line? 1 Answer

Fix gun so it moves with the character correctly when changing animations 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