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 /
  • Help Room /
avatar image
0
Question by djcrum1107 · Dec 04, 2015 at 02:21 AM · 2d-platformerlinerendererdisappearing

Keep LineRenderer from changing width in 2D

So I have seen quite a few issues with LineRenderer but none of them answer my issue and I have been unable to find a source in the forums, manuals, or script examples. So my issue is:

  1. Using LineRenderer for the red sight of a gun in a 2D shooter

  2. Red sight goes from gun (its parent object) to mouse pointer using CameraToWorldPoint

  3. Looking through scene view the beam is always there, but in game view it slims down to nothing based on the position.

The code is simple in my head but it doesn't want to work correctly. Anyone know what causes this or need more information for what I messed up?

mouse_pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); snipeTrail.SetPosition(0, transform.position); snipeTrail.SetPosition(1, Camera.main.ScreenToWorldPoint(Input.mousePosition));

Adding an image to show this, scene view different than game view: image

scopebugimage.jpg (208.3 kB)
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

Answer by thirdcoke · Jan 26, 2016 at 08:45 AM

I'm not familiar with your scene, but I create an example myself, hope this will help. Create a new scene, create a cube, attach the script on the cube. Then click Play link text


linetest.zip (1.0 kB)
Comment
Add comment · Show 2 · 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 djcrum1107 · Jan 28, 2016 at 02:37 AM 0
Share

While not directly helping it did create the bridge to help me figure it out. I ran your line on a new scene attached to a cube and was able to get the line rendered in full. Since I was running it in 3d mode I was able to see to rotation of the line which the camera always sees in full from the front. Long story short: I focused on the camera ins$$anonymous$$d of the LineRenderer and found that adding a vector to account for the "screentoworldpoint" being at the camera along the z axis it would distort it the game view. Even shorter: snipeTrail.SetPosition(1, Camera.main.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0, 0, 10)); with the 10 in the new vector being the camera depth that will be changed to a reference over hardcoding it. Extra tidbit: learned about RequireComponent in scripts Thanks!

avatar image djcrum1107 · Jan 28, 2016 at 02:37 AM 0
Share

While not directly helping it did create the bridge to help me figure it out. I ran your line on a new scene attached to a cube and was able to get the line rendered in full. Since I was running it in 3d mode I was able to see to rotation of the line which the camera always sees in full from the front. Long story short: I focused on the camera ins$$anonymous$$d of the LineRenderer and found that adding a vector to account for the "screentoworldpoint" being at the camera along the z axis it would distort it the game view. Even shorter: snipeTrail.SetPosition(1, Camera.main.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0, 0, 10)); with the 10 in the new vector being the camera depth that will be changed to a reference over hardcoding it. Extra tidbit: learned about RequireComponent in scripts Thanks!

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

36 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

Related Questions

Linerenderer BUG,Problem with the LineRenderer.. 1 Answer

Drawing a "rope" when the player jumps while not grounded 0 Answers

Fall Through Platform Script? 0 Answers

Proper way to update enemies in a large 2d level. 1 Answer

Make Character Selection 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