• 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 /
  • Help Room /
avatar image
0
Question by myrobishow_unity · Dec 26, 2017 at 03:05 PM · instantiatepositioningrelative

[SOLVED] Help please: My laser instances are not following my player

Hello Dear Community, would you please come to my help. I'm new at development and I'm facing a problem that I can't explain or fix...

My lasers (sprites instantiate from a position relatives to my ship) are not following my ship in the way they should do .. The thing that I cannot understand is that they seems to not follow the same distance scale of the ship, this is why I say that:

When my ship is on the right-side of the screen, they appear even more on the right, when my ship is on the left-side, they appear even more on the left. The same happen for up and down .. Its only when my ship is on the middle that they appeear at the right place.

BUT, MORE WEIRD, in the Scene View they seems to be at the right place at any time But not in the Game View (where the problem occur)

You can see the following images:

https://ibb.co/e1mv76

https://ibb.co/dyGv76

https://ibb.co/gT8WfR

 void Update() {

     //Set the position of the lasers
     posLaser1 = new Vector3(transform.position.x - 0.75f, transform.position.y + 0.5f, 0);
     posLaser2 = new Vector3(transform.position.x + 0.75f, transform.position.y + 0.5f, 0);

}

     void Fire(){
         GameObject projectile = Instantiate(beam, posLaser1, Quaternion.identity) as GameObject;
         GameObject projectile1 = Instantiate(beam, posLaser2, Quaternion.identity) as GameObject;
 
         projectile.GetComponent<Rigidbody2D>().velocity = new Vector3(0, beamSpeed, 0);
         projectile1.GetComponent<Rigidbody2D>().velocity = new Vector3(0, beamSpeed, 0);
 
         AudioSource.PlayClipAtPoint(shoot, transform.position);
 
         flash1.Play();
         flash2.Play();

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by myrobishow_unity · Dec 26, 2017 at 03:46 PM

I fixed my problem alone by adding a reference to the object I wanted my lasers to be relatives to (my Ship) and THEN adding the right positioning that I wanted. Here's my code: posLaser1 = gameObject.transform.position + new Vector3(- 0.75f, + 0.7f, 0); posLaser2 = gameObject.transform.position + new Vector3(+ 0.75f, + 0.7f, 0);

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

138 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 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

Unable to set position of instantiated prefab 1 Answer

How to instantiate Object to specific location? 1 Answer

Instantiating a GameObject relative to another object's position and rotation 1 Answer

Instantiate position for shooting projectile is way off. Could I get some help? 0 Answers

my instantiation script works sometimes but not all.. why? 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