• 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
Question by ticofa · Mar 22, 2015 at 11:06 AM · rotationprefab

Instantiating object with transform.rotation not working?

 if (Vector2.Angle (transform.forward, other.transform.position - transform.position) < 1) {
             _shotTimer += 1 * Time.deltaTime;
             if(_shotTimer > 0.2)
             {
                         if (_whichWeapon) {
                     _laserobj = Instantiate (_laser, _position.transform.position, _position.transform.rotation) as GameObject;
 
                     
                                 _shotTimer = 0;
                     _whichWeapon = false;
                         } else {
                     _laserobj = Instantiate (_laser, _position2.transform.position, _position2.transform.rotation) as GameObject;                    
                                 _shotTimer = 0;
                     _whichWeapon = true;
                         }
             }
                 } else {
             _shotTimer = 0;
                 }

So, i have a little spaceship, really small, scale factor 0.003... What i want to happen is, when it shoots a laser, the laser has the same rotation as the objects referenced in the variables (_position and _position2)... The thing is..., unless the ship is facing 0,0,0 rotation, the laser is instantiated with and odd rotation... This happens:

alt text

alt text

Is any thing wrong with the instantiation code?

tha-hell.png (84.6 kB)
near-0.png (154.9 kB)
Comment

People who like this

0 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 siaran · Mar 22, 2015 at 04:25 PM 1
Share

What are position and position2 in that code?

I'll just assume they are gameobjects that are children of your fighter object that serve as launch positions for your laser object, because that would make sense.

In which case, your instantiation code looks fine afaict. Maybe the problem is in the laser object? How does it move?

avatar image ticofa · Mar 23, 2015 at 11:02 PM 0
Share

Ahah, i just found the problem xD! Befour i explain my self, i should thank you and possibly future anwers :D!

The problem was in the script that managed the laser movement, i had this to move:

transform.translate (transform.forward nº time.deltaTime);

and i forgot to put the "space.World" after that, wich caused the laser to move the wrong direction... the initial direction it was instantiated was right :D!

Again thank you ;)!

How do i close this question? if it has that option xD?

avatar image ticofa · Mar 24, 2015 at 01:18 AM 0
Share

Dang! I also forgot to say that those two variables "position" and "position2" are indeed the positions for the instantiated lasers xD

0 Replies

  • Sort: 

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unespected rotation for Instantiate object 1 Answer

Prefab transform will only rotate when placed manually in the scene. Does not work on instantiation. 0 Answers

Preventing parts of a prefab from rotating w/parent? 0 Answers

Instantiating prefab of object like it was in the scene 0 Answers

Trouble rotating a prefab while it's moving up,Rotating an object with an animation while it moves up 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