• 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 michael 4 · Apr 22, 2011 at 08:12 PM · vector3mathlinebox

Basic vector math addition

I feel like I should know this because we went over it in calculus 3 but Im having hardest time getting my vector math to work.

Basically I need to draw a box in the editor based off of this information

public int boundaryLength = 10;

public int boundaryWidth = 10;

public GameObject boundaryStart; // where to start drawing from

I then try to draw the box with the following code

void OnDrawGizmos () { //draw a greenbox around the boundary area if(visualizeGrid == true) { //draw a a green boundary box Vector3 point_1 = boundaryStart.transform.position; Vector3 point_2 = new Vector3(boundaryStart.transform.position.x + boundaryLength,0,0); Vector3 point_3 = new Vector3(boundaryStart.transform.position.x + boundaryLength, 0, boundaryStart.transform.position.z + boundaryWidth); Vector3 point_4 = new Vector3(0, 0, boundaryStart.transform.position.z + boundaryWidth);

     Gizmos.color = Color.green;
     Gizmos.DrawLine(point_1, point_2);
     Gizmos.DrawLine(point_2, point_3);
     Gizmos.DrawLine(point_3, point_4);
     Gizmos.DrawLine(point_4, point_1);      
 }
 else
 {
     return; //if visualize gride is turned of, exit function    
 }

}

This to me seems like it should draw, but I get this weird quadrilateral that is a half box half...not box

Maby my math is wrong but i cant seem to see where

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 michael 4 · Apr 22, 2011 at 08:16 PM 0
Share

Well I found out that it perfectly works as long as the starting point is exactly at (0,0,0) but when you move the starting point around things get messed up

avatar image DaveA · Apr 22, 2011 at 08:19 PM 0
Share

Are you trying to draw a 2D box around the object in Editor windows? No matter what the camera orientation?

1 Reply

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

Answer by DaveA · Apr 22, 2011 at 08:20 PM

Vector3 point_4 = new Vector3(0, 0, boundaryStart.transform.position.z + boundaryWidth);

Your x,y for this is always zero. transform.position is in world coords. I think you want some thing more like:

Vector3 point_4 = new Vector3(boundaryStart.transform.position.x, 0, boundaryStart.transform.position.z + boundaryWidth);

In other words, your 'local origin' will be transform.position.x and z, and the offsets will be position.x + length and .z + width.

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

No one has followed this question yet.

Related Questions

Angle between two lines in 2D 3 Answers

Reverse of this function? 0 Answers

how do i keep a gameobject in between the union of 2 or more than 2 circles 0 Answers

Finding Nearest Object Both Positive And Negative? 1 Answer

Given a vector, how do i generate a random perpendicular vector? 5 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