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 pumpkinszwan · Feb 05, 2015 at 11:25 AM · 2dquaternionangleline

How can I draw a line at a specific angle?

I want to draw two lines from the same origin but at specific angles relative to an original line (to form a field of view). How do I do this? In 2D space FWIW.

In the image below, the three lines (purple, 2x orange) would extend from the 'eye' transform at the tip of the triangle. The purple line is directly 'up' or 'forward' with the orange ones at 65 degrees on either side. The lines need to rotate with the parent transform.

The purple line is just a direct line drawn between the tip of the triangle and another child transform, which I achieve at runtime using a simple Debug.DrawLine.

alt text

I've seen a few answers on here for similar queries, but they have not been exactly the same problem, and since I don't understand quaternions very well I can't adapt those answers to my problem.

I think Quaternion.AngleAxis is the key, but I can't figure out what to give it to get the results I need.

I've tried the code given here: http://answers.unity3d.com/questions/42300/draw-line-to-a-specific-angle.html, but it doesn't seem to work (I don't understand exactly what the code is doing so I can't adapt it to my needs).

eyes.png (9.1 kB)
Comment
Add comment · Show 1
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 sniper43 · Feb 05, 2015 at 12:59 PM 0
Share

$$anonymous$$aybe you can use Quaternion.Euler if you understand angles?

Edit the link, there's an unwanted appended comma there.

Also a note: you can use vectors ins$$anonymous$$d of angles to draw lines.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by daneislazy · Feb 05, 2015 at 02:44 PM

So I wrote a long thing about using the example you gave and Debug.DrawLine to accomplish your task. Then I realized that you probably don't want to use Debug things in final code so that isn't helpful. And then I realized that there are other easier solutions to your issue that I was ignoring because I was trying to explain Quaternion.AngleAxis.

Firstly tldr of what I initially wrote:

-in the Quaternion.AngleAxis example the transform.up is the vector to be rotated around so you would need Vector3.forward instead. Then multiply it by the line(he's missing an *)

-the line vector just needs to be whatever is your local facing/forwards, so in 2D it's probably transform.up because that's what it looks like in your image(green gizmo line).

-assuming you are rotating the whole game object that should be correct it will probably be length 1 so you can multiply it by a float to change the length.

But you don't really need to worry about that.

Actual Answers:

Since you are working in 2D you could just make a sprite image of the lines you need and make them child objects of your main gameObject. So that when it rotates they do as well, and are in the correct locations/rotation.

You can also do almost the same thing with the Line Renderer http://docs.unity3d.com/Manual/class-LineRenderer.html

Just add a couple of these and set up the points to where you need them. Remember to uncheck Use World Space at the bottom of the component in the inspector. If you don't they will just be stuck at the world space co-ordinates.

Hope that helps/works!

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.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Finding the angle between 2 clicked points 2 Answers

follow an object's x-axis and have it translate smoothly into another object's z-axis rotation 1 Answer

Camera direction depending on targets slope (X axis) 0 Answers

How to create a 2D line between a Game Object and the mouse? 0 Answers

Quaternion and rotation angles 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