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 Satamanster · Jul 10, 2012 at 06:54 PM · rigidbodyinstantiatequaternionbulletmissile

Bullet always facing the sky.

Ok people, once again i'm here bagging on my knees for your help. So here's the deal. I have this Tank that is supposed to shoot missiles and here's what i have.

 @script ExecuteInEditMode()
 
 var bulletPrefab: Transform ;
 var tirosDisparados: int =0;
 var bulletSpeed: float = 60;
 var buttonX: int = 0;
 var buttonY: int = 0;
 
 function Update()
 {
  if (Input.GetButtonDown("Fire1"))
  {
  var shoot = Instantiate(bulletPrefab,GameObject.Find("Spawn").transform.position,Quaternion.identity);
  shoot.rigidbody.AddForce(GameObject.Find("Spawn").transform.forward * bulletSpeed);
 //Bullet Counting
  tirosDisparados = tirosDisparados + 1;
  Debug.Log(tirosDisparados);
 
  
  }
 }

The problem is, no matter the rotation of the prefab, my missile always faces to the sky, I believe it's something related to the quaternion, but since, i don't know how to work with it (i'm a noob), i'm asking for your help... Hope you can help me. Thanks once again to this wounderfull community.

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
0
Best Answer

Answer by fafase · Jul 10, 2012 at 07:05 PM

Quaternion.identity is short for no rotation.

Try this one:

 var spawn:GameObject;

 //This is creating a reference to the spawn object for faster access.
 function Start(){
    spawn =GameObject.Find("Spawn");}
 
 var shoot =Instantiate(bulletPrefab,spawn.transform.position, spawn.transform.rotation);
  shoot.rigidbody.AddForce(spawn.transform.forward * bulletSpeed);
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 Satamanster · Jul 12, 2012 at 01:45 AM 0
Share

Thanks, it didn't work but the idea of finding the object on the start was a very good hint, thanks.

avatar image
0

Answer by nventimiglia · Jul 10, 2012 at 07:09 PM

You are using Quaternion.identity (zero)

  if (Input.GetButtonDown("Fire1"))
  {
      var spawn = GameObject.Find('Spawn');
      var shoot = Instantiate(bulletPrefab, spawn.transform.position, spawn.transform.rotation);
      shoot.rigidbody.AddForce(spawn .transform.forward * bulletSpeed);
     //Bullet Counting  
     tirosDisparados = tirosDisparados + 1;
     Debug.Log(tirosDisparados);   
  }

Another thing, you really shouldent Find the gameobjects like that. Its best you cache the spawn object on awake.

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 Satamanster · Jul 12, 2012 at 01:44 AM 0
Share

That didn't solve my problem but you were right about spawing objects on the go, anyway, for now, i made it to shoot balls so there is no problem after all... I'll check on this later...

avatar image
0

Answer by Satamanster · Jul 10, 2012 at 08:45 PM

For fafase and nventimiglia :

Using the spawn rotation fixes it... Or not, well, if i rotate the spawn now, x axis makes my missile being shoot upwards or downwards, the y one, makes it shoot more to the left or to the right, and only z makes the bullet rotate, in this case the wrong direction, since now instead of being always facing up, is always facing left, as i set the spawn z rotation to 90...

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Bullet hell - how to make a lot of bullets? 3 Answers

My 2d spawned bullet prefabs will not fly up, just fall 3 Answers

Bullet Spawning Problem 1 Answer

Gun is shooting based on movement not camera rotation? 1 Answer

Projectile not moving properly in top down 2d shooter 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