• 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 Janjanus · Sep 22, 2015 at 01:31 PM · unity 5linerendererforwarddrawline

Draw a line in forward direction of a object

I am trying to draw a line between the translate.forward direction and a point 20 unit further then the translate.forward point. This is the code I use (I added the LineRenderer component to the object):

 LineRenderer lineRenderer = mHead.GetComponent<LineRenderer>();
 lineRenderer.SetPosition(0, transform.position);
 lineRenderer.SetPosition(1, transform.forward * 10);

This is not working correctly (I think). Since when I use the Debug.DrawRay(...) it gives me another line code:

 Debug.DrawRay(transform.position, transform.forward * 10, Color.red, 0);

Does anyone knows how to do this correctly?

Comment
Add comment · Show 4
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 sys12 · Sep 22, 2015 at 01:56 PM 0
Share

What do you mean by drawing a line between a direction and the direction * 20?

avatar image Janjanus sys12 · Sep 22, 2015 at 01:57 PM 0
Share

I have updated the question, I hope it is more clear now!

avatar image sys12 Janjanus · Sep 22, 2015 at 02:01 PM 1
Share

Do you mean you want a line between your current position and 20*facing direction away from your current position? Try this:

 LineRenderer lineRenderer = mHead.GetComponent<LineRenderer>();
 lineRenderer.SetVertexCount(2);
 lineRenderer.SetPosition(0, transform.position);
 lineRenderer.SetPosition(1, transform.forward * 20 + transform.position);

Don't forget to set the color of the LineRenderer.

Show more comments

1 Reply

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

Answer by Janjanus · Sep 22, 2015 at 02:43 PM

@sys12 suggested to change the code to:

  LineRenderer lineRenderer = mHead.GetComponent<LineRenderer>();
  lineRenderer.SetVertexCount(2);
  lineRenderer.SetPosition(0, transform.position);
  lineRenderer.SetPosition(1, transform.forward * 20 + transform.position);

This worked perfectly! Thanky You @sys12!

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

33 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

Related Questions

Making Raycast line visible 2 Answers

Line renderer broken with SteamVR? 2 Answers

Round a Line around a round thing 0 Answers

how make object follow mouse cursor in 3d space 0 Answers

Line Renderer looks different in Game View to Scene View 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges