• 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 mpark · Apr 01, 2012 at 05:04 PM · directionangledrawray

Draw af line in a specific angle around an object

Hi. I have a transform which I can draw a Ray from using e.g. Gizmos.DrawRay. My problem is that I don't know how to define an angle instead of a direction.

E.g. I can understand that transform.forward - transform.right will send it 90 degrees to the left - but how do I say "draw a line in 12 degrees to the right of transform.forward"?

With regards mpark

Comment
Add comment · Show 2
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 armoredpokey · Apr 01, 2012 at 07:28 PM 0
Share

Hmm. I don't know if this is a solution to your problem, but you might find these functions helpful: Vector3.Slerp, Vector3.RotateTowards.

Since transform.forward and transform.right are both Vector3s, it should be possible with either of those functions to get a Vector3 which is transform.forward rotated 12 degrees towards transform.right in the plane defined by the two vectors. You might be able to pass that in in some useful capacity to Gizmos.

avatar image Bunny83 · Apr 01, 2012 at 08:13 PM 0
Share

Just a side note: Debug.DrawList / Ray and Gizmos.DrawLine / Ray are only available in the editor since they are either debug functions or part of the editor. Hopefully you work on a editor extension.

1 Reply

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

Answer by Owen-Reynolds · Apr 01, 2012 at 09:32 PM

You can rotate the line segment by 12 degrees, using a quaternion (Angles are made with Quaternions.) To make a 12 degree y-rotation, use: Quaternion y12degs = Quaternion.Euler(0,12,0); The result, y12degs can be used to "hit" any Vector3 and spin it. So:

 Vector3 lineEnd = transform.forward;
 // NOTE: lineEnd is a short line acting as if I was at (0,0,0)
 
 Quaternion y12degs = Quaternion.Euler(0,12,0);
 // This is odd. You apply the 12 degree rotation to a point by multiplying:
 lineEnd = y12degs * lineEnd;

 // bring it back to world coords:
 // NOTE: if line should be longer, scale it anytime before this
 lineEnd = lineEnd + transform.position;

There are lots of special purpose functions for doing this. But using quaternions is just one trick to learn that can solve just about anything, and is at worst only a little longer than some "cool" way.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Move infinitely in targeted direction 3 Answers

3rd person unit control 0 Answers

How to add slight angle/rotation variation to transform.forward? 5 Answers

Random /Organic/ Weapon Inaccuracy 1 Answer

Set an angle for bouncing 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