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
0
Question by mitti2000 · Apr 14, 2018 at 05:13 AM · rotationshootingbullet

Shoot bullet in direction which player looks

Hi there

I just started again with Unity (did some stuff a few years back) and I have a problem now which I can't solve.

I want to shoot bullets in the direction the player is looking.

I have following setup: Player --Camera --gunBarrel

I have a player script attached to the Player which instantiates the bullets.

playerScript.cs

 public class PlayerScript : MonoBehaviour
 {
 
     public float MovementSpeed = 1;
     public GameObject bullet;
     private GameObject _bullet;
     public Transform gunBarrel;
 
     void Start ()
     {
     }
     
     void Update () {
 
         if (Input.GetButtonDown("Fire"))
         {
             _bullet = Instantiate(bullet, transform.position, transform.rotation);
         }
     }
 }

In the inspector, the player rotates as it should. But the instantiated bullets have a rotation of (3.8,0,0). If I Debug.Log(transform.rotation) I always get 0,0,0 no matter how the player is rotated. Can somebody explain me, what I am doing wrong?

Thanks, mitti2000

Comment
Add comment · Show 3
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 Captain_Pineapple · Apr 14, 2018 at 08:28 AM 0
Share

Do you actually rotate the object with the PlayerScript attached? Or do you rotate some child object with the visuals attached?

avatar image mitti2000 Captain_Pineapple · Apr 14, 2018 at 08:49 AM 0
Share

I'm using the Smeeoth$$anonymous$$ouseLook Script (http://wiki.unity3d.com/index.php/Smooth$$anonymous$$ouseLook) Which is attached to the player. The player script is also atteched to the player. In the inpector I see the rotation changes on the player. Does that answer your question?

avatar image Captain_Pineapple mitti2000 · Apr 14, 2018 at 09:13 AM 0
Share

Hey,

i just recreated your setup and for me everything works. You could try to remake your setup from scratch just to be sure that there is no mistake in it.

I took a cube, attached the smoovemouseLookScript with default values and gave it the camera as a child. Then i attached another script to the Cube that only does a debug.Log(transform.rotation.eulerAngles) in Update. For me this works and provides the correct Angles.

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

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

Related Questions

Bullet Rotation faces wrong direction 2 Answers

Problem with Shooting Accuracy 0 Answers

Need help with Transform.LookAt 1 Answer

shoot bullet on a moving gameobject 0 Answers

Bullet flies away for no apparent reason. 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