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 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
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 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. $$anonymous$$aybe 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

· 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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Physics related rotation problem. (a weird one) 0 Answers

Freeze object rotation on Polybrush 1 Answer

Instantiated Object looses prefab's rotation 10 Answers

Can't reference Camera in Prefab 1 Answer

Move prefab in the direction its facing (2D) 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