Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by kaliban · Jun 02, 2013 at 01:26 PM · vector3debugdrawline

How to debug drawing plane?

I'm kinda new to vector math, I can't figure out how to debug following plane:

Plane playerPlane = new Plane(transform.position+ transform.forward,transform.position);

I understand, that there must be four debug.drawline, but I dont know how to get vector3 for them...

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

2 Replies

· Add your reply
  • Sort: 
avatar image
11

Answer by robertbu · Jun 03, 2013 at 03:20 AM

If you take the cross product of a normal to the plane and any vector that is not colinear (parallel with) with the normal, you will get a vector on the plane. Then you can rotate that vector by 90 degrees using the normal as an axis to other vectors. Here is a bit of code. It draws a square with an X through it on the plane in green and the normal in red. The size of the square is the magnitude of the normal passed in. Planes are infinite, so the square is only to help visualize the plane, not define any kind of boundary.

 function DrawPlane(position : Vector3, normal : Vector3) {
 
 var v3 : Vector3;
 
 if (normal.normalized != Vector3.forward)
     v3 = Vector3.Cross(normal, Vector3.forward).normalized * normal.magnitude;
 else
     v3 = Vector3.Cross(normal, Vector3.up).normalized * normal.magnitude;;
     
 var corner0 = position + v3;
 var corner2 = position - v3;

 var q = Quaternion.AngleAxis(90.0, normal);
 v3 = q * v3;
 var corner1 = position + v3;
 var corner3 = position - v3;
 
 Debug.DrawLine(corner0, corner2, Color.green);
 Debug.DrawLine(corner1, corner3, Color.green);
 Debug.DrawLine(corner0, corner1, Color.green);
 Debug.DrawLine(corner1, corner2, Color.green);
 Debug.DrawLine(corner2, corner3, Color.green);
 Debug.DrawLine(corner3, corner0, Color.green);
 Debug.DrawRay(position, normal, Color.red);
 }

There are likely less computationally expensive ways to solve this problem, but this should work fine for debugging.

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 aybeone · Jun 30, 2015 at 09:39 PM 0
Share

very good, thanks !

avatar image Xyy_1209 · Dec 24, 2019 at 02:00 AM 0
Share

Hi, I have tried your method, it works. I have a question, in line 4 and 6, what does normal.magnitude effect? The normal size of a plane in unity is 1? So I don't know the function of mormal.magnitude.

avatar image
0

Answer by ModelOX · Jun 03 at 07:38 PM

here's a c# version since I find myself coming back to this often

    public void DrawPlane(Vector3 position, Vector3 normal)
     {
         Vector3 v3;

         if (normal.normalized != Vector3.forward)
             v3 = Vector3.Cross(normal, Vector3.forward).normalized * normal.magnitude;
         else
             v3 = Vector3.Cross(normal, Vector3.up).normalized * normal.magnitude; ;

         var corner0 = position + v3;
         var corner2 = position - v3;
         var q = Quaternion.AngleAxis(90.0f, normal);
         v3 = q * v3;
         var corner1 = position + v3;
         var corner3 = position - v3;

         Debug.DrawLine(corner0, corner2, Color.green);
         Debug.DrawLine(corner1, corner3, Color.green);
         Debug.DrawLine(corner0, corner1, Color.green);
         Debug.DrawLine(corner1, corner2, Color.green);
         Debug.DrawLine(corner2, corner3, Color.green);
         Debug.DrawLine(corner3, corner0, Color.green);
         Debug.DrawRay(position, normal, Color.red);
     }
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

16 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

Related Questions

OnDrawGizmos Debug.DrawLine position is pinching when rotated. 0 Answers

Selecting custom game objects in Scene view window. 1 Answer

Cast ray relative to the direction my Object is moving 1 Answer

What do Vector3s do in a ray? 1 Answer

Mesuring distance through script 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