Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by colopto · Jun 28, 2011 at 07:06 PM · rotationbullet

Problem with bullet not rotating with gun

My bullet dose not rotate with the gun when i fire (i rotate the gun in play mode and the bullet still comes out like its facing forward)

heres my script

 var bulletPrephab : Transform ;
 
 function Update () {
 
 
     if(Input.GetButtonDown("Z"))
     {
         var bullet = Instantiate(bulletPrephab, GameObject.Find("Spawn Point") . transform.position, Quaternion.identity);
     
         bullet.rigidbody.AddForce(transform.forward * 2000);
     
     }
 
 
 }
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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Borgo · Jun 28, 2011 at 07:51 PM

Maybe works if you apply the same object rotation:

 var bullet = Instantiate(bulletPrephab, GameObject.Find("Spawn Point") . transform.position, transform.rotation);

Try to change the Quaternion.identity to transform.rotation.

Sorry if I don't understand the question.

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 $$anonymous$$ · Nov 14, 2014 at 04:50 AM 0
Share

helpful for rotating the bullets, but they still don't travel in the correct direction

avatar image
-1

Answer by colopto · Jun 29, 2011 at 06:54 AM

You sir are a genius

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 GuyTidhar · Jun 28, 2011 at 07:35 PM

You should look at the axis of your bulletPrefab and notice how the bullet is faced compared to its axis. For instance, notice the blue axis - is it along the bullet length pointing the same direction the bullet does? (probably not since you have this question). http://unity3d.com/support/documentation/ScriptReference/Transform-forward.html

You can add an empty game object as a parent to the bullet prefab while rotating the empty game object before doing so, so that its forward vector (blue) will point like the bullet does, then make the bullet prefab the child. Next, you should create a new bullet prefab out of this hierarchy and drag this prefab to your script.

Now, if your bullet is not rotated as you wish do

 bullet.transform.forward = transform.forward;

After you call the "Instantiate", and your bullet should be fine.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Predict where object will be 2 Answers

bullet rotation as its affected by gravity 2 Answers

Help with gun accuracy in degrees. 3 Answers

Create sprite in place of cursor that has 'lag' on it? 0 Answers

Bullets. Rotation Probelm 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