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 Rocky1234321 · Jul 30, 2014 at 09:17 AM · sizeboundsworldlocalspace

Question about finding out edges of a box collider

Okay this is really annoying for me since i want to do a pathfinding script designed for my own game and don't want to use somebody else's cuz i want some practice. I have figure out my algorithm and kinda want to put it into action. THe problem now is that i cant find a way to find out the edges of box colliders for the algorithm to work all i need is the world space size of the box. I know you can do it by raycasting your entire map blablabla, but its kinda unnecessary for my algorithm. I just want to know the size of the box in world space or somehow get the coordinates of the 4 vertical edges of a box collider;

I have learned how to find out all the other data already. Or is there another way of doing it? Im using mathmatical approach by looking at boxcollider top down so it becomes a rectangle. turn the 4 sides into 4 function and whenever they intersect they provide me a x,z position of the box collider. They great thing about it is that it tells me which side of the cube did the raycast contact as well. I have examine my formula and algorithm in 3js for another game and it works. Here is some of it.

so data[3] and data[4] were suppose to the world space size of the box collider; abcd are the 4 points and xz in this program is instead xy. poi is point of impact data[1] data[2] is the center of the collider and 5 is the eulerangle in radius

float[] FindPoints( float[] data , Vector3 poi){ Debug.Log (data[3]+" "+data[4]+" "+cs[3]+" "+cs[4]); float[] edges= new float[4]; float x=0; float y=0; float x1,y1=0; x1= poi.x-data[1]; y1= poi.y-data[2]; Debug.Log (y1+" "+x1); // find which side its on if(y1==x1*(Mathf.Tan(Mathf.PI/2-data[5]))+data[3]/Mathf.Sin (data[5])){ Debug.Log ("1"); //ax edges[0]=(data[4]/Mathf.Cos(data[5])-data[3]/Mathf.Sin(data[5]))*Mathf.Tan(Mathf.PI/2-data[5]); //dx edges[1]=(-data[4]/Mathf.Cos(data[5])-data[3]/Mathf.Sin(data[5]))*Mathf.Tan(Mathf.PI/2-data[5]); //ay edges[2]=edges[0]/(Mathf.Tan(Mathf.PI/2-data[5]))+data[3]/Mathf.Sin (data[5]); //dy edges[3]=edges[1]/(Mathf.Tan(Mathf.PI/2-data[5]))+data[3]/Mathf.Sin (data[5]);

 }
 else if(y1==x1*(Mathf.Tan(Mathf.PI/2-data[5]))-data[3]/Mathf.Sin (data[5])){
     Debug.Log ("2");
     //ax
     edges[0]=(data[4]/Mathf.Cos(data[5])-data[3]/Mathf.Sin(data[5]))/Mathf.Tan(Mathf.PI/2-data[5]);
     //bx
     edges[1]=(data[4]/Mathf.Cos(data[5]+data[3])/Mathf.Sin(data[5]))/Mathf.Tan(Mathf.PI/2-data[5]);
     //ay
     edges[2]=edges[0]/(Mathf.Tan(Mathf.PI/2-data[5]))+data[3]/Mathf.Sin (data[5]);
     //dy
     edges[3]=edges[1]/(Mathf.Tan(Mathf.PI/2-data[5]))+data[3]/Mathf.Sin (data[5]);

 }
 else if(y1==x1*(Mathf.Tan(data[5]))+data[3]/Mathf.Cos(data[5])){
     Debug.Log ("3");
     //bx
     edges[0]=(data[4]/Mathf.Cos(data[5]+data[3])/Mathf.Sin(data[5]))/Mathf.Tan(Mathf.PI/2-data[5]);
     //cx
     edges[1]=(-data[4]/Mathf.Cos(data[5])+data[3]/Mathf.Sin(data[5]))/Mathf.Tan(Mathf.PI/2-data[5]);
     //ay
     edges[2]=edges[0]/(Mathf.Tan(Mathf.PI/2-data[5]))+data[3]/Mathf.Sin (data[5]);
     //dy
     edges[3]=edges[1]/(Mathf.Tan(Mathf.PI/2-data[5]))+data[3]/Mathf.Sin (data[5]);
 }
 else if(y1==x1*(Mathf.Tan(data[5]))-data[3]/Mathf.Cos(data[5])){
     Debug.Log ("4");
     //cx
     edges[0]=(-data[4]/Mathf.Cos(data[5])+data[3]/Mathf.Sin(data[5]))/Mathf.Tan(Mathf.PI/2-data[5]);
     //dx
     edges[1]=(-data[4]/Mathf.Cos(data[5])-data[3]/Mathf.Sin(data[5]))/Mathf.Tan(Mathf.PI/2-data[5]);
     //ay
     edges[2]=edges[0]/(Mathf.Tan(Mathf.PI/2-data[5]))+data[3]/Mathf.Sin (data[5]);
     //dy
     edges[3]=edges[1]/(Mathf.Tan(Mathf.PI/2-data[5]))+data[3]/Mathf.Sin (data[5]);
 }
 Debug.Log (x1*(Mathf.Tan(Mathf.PI/2-data[5]))+data[3]/Mathf.Sin (data[5]));
 Debug.Log (x1*(Mathf.Tan(Mathf.PI/2-data[5]))-data[3]/Mathf.Sin (data[5]));
 Debug.Log (x1*(Mathf.Tan(data[5]))+data[3]/Mathf.Cos(data[5]));
 Debug.Log (x1*(Mathf.Tan(data[5]))-data[3]/Mathf.Cos(data[5]));
 edges[0]+=data[1];
 edges[1]+=data[1];
 edges[2]+=data[2];
 edges[3]+=data[2];
 return edges;

}

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 meat5000 ♦ · Jul 30, 2014 at 09:17 AM 0
Share

You should be able to read off the size using this

http://docs.unity3d.com/ScriptReference/BoxCollider-size.html

avatar image ShadoX · Jul 30, 2014 at 09:18 AM 0
Share

or http://docs.unity3d.com/ScriptReference/Renderer-bounds.html or http://docs.unity3d.com/ScriptReference/Bounds.html

avatar image meat5000 ♦ · Jul 30, 2014 at 09:20 AM 0
Share

Indeed; for a box, bounds should match the collider itself :) Note this method is not so repeatable for Spheres etc, but still perfectly valid.

avatar image Rocky1234321 · Jul 30, 2014 at 04:24 PM 0
Share

the problem is if i rotate the box it will give a different result since it is making a new box trying to contain it? at least thats how it seems to me. I tried to use the box collider but it doesn't allow me since im using raycasthit and there doesnt seems to be a option of using boxcollider

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

What is the difference between transform.up and Vector3.up? 1 Answer

Get position of the centre of each grid tile 1 Answer

max dimensions of Unity world space (bounds for the x,y,z values of vector3)? 2 Answers

Print bounds size. 3 Answers

Matching an object's size 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