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 Hyperion · Mar 25, 2013 at 01:55 AM · linerendererlaser

LineRendering Forward

Hi everyone,

I have robots that shoot lasers. Currently, they shoot at the character.

 Laser.SetPosition(0, Cero.position);
 Laser.SetPosition(1, Victim.position);

(BTW, Cero is the point out of which they're shooting.)But I want them to shoot forward on their Z axis. So I did:

 Laser.SetPosition(0, Cero.position);
 Laser.SetPosition(1, Vector3.fwd);

But instead of shooting on their z axis, they're shooting off to some random spot:alt text

And in the picture, it's hard to see, but that robot is shooting to his right.

What's the issue, and is there a way to make them simply shoot a linerenderer forward?

issue.png (86.8 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
1
Best Answer

Answer by robertbu · Mar 25, 2013 at 03:04 AM

I assume that "Vector3.fwd", you mean "Vector3.forward". Vector3.forward, is a zero based, and has a length of one, so you are pointing near the origin. I assume from your first two lines, that you have "Use World Space" checked in the line renderer. If so, you want these two lines instead:

 Laser.SetPosition(0, Cero.position);
 Laser.SetPosition(1, Cero.position + Vector3.forward * distance);

'distance' is a variable you set (or a constant you insert) that represents the distance in form of Cero you want the LineRenderer to end.

Comment
Add comment · Show 9 · 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 Loius · Mar 25, 2013 at 03:34 AM 0
Share

I think you want Cero.forward (forward relative to Cero) rather than Vector3.forward (forward relative to zero). :)

avatar image robertbu · Mar 25, 2013 at 03:37 AM 0
Share

@Louis, You may be right, but he says in the question "forward on their Z axis," so I coded it this way. @Hyperion, if you mean forward of the character, then:

Laser.SetPosition(1, Cero.position + Cero.forward * distance);

avatar image Hyperion · Mar 26, 2013 at 01:02 AM 0
Share

Thanks for your guys' help. Now I'm using

 Laser.SetPosition(0, Cero.position);
 Laser.SetPosition(1, Cero.position + Cero.forward * Lazdist);

And the lazer goes in the right direction. But now, the lazer isn't long enough, even if I change distance to 1000. What's the issue? alt text

avatar image Benproductions1 · Mar 26, 2013 at 01:45 AM 0
Share

If this is answered, please accept the right answer, by selecting the tick under the thumbs down button :)

avatar image Hyperion · Mar 26, 2013 at 02:19 AM 0
Share

@Benproductions1: It hasn't been fully answered, but I of course will accept the answer when my second question has been answered (up above)

Show more comments

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

12 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

Related Questions

How to get a LineRenderer to shoot from Gun Point to Mouse Position 1 Answer

Dynamically adjusting LineRenderer vertexes to follow raycasts 0 Answers

Line Renderer. How to lock z axis for side scroller? 1 Answer

LineRenderer End Width Bug 2 Answers

Laser Render Reflect Angle incorrect 1 Answer


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