- Home /
Calculating collider corners
Hi, i try calculating the corners of a collider, my script work only as long the object didn't rotate. The object rotate, but the collider stay on his original rotation. What do i miss?
     public float[] convertToScreenPos(Collider collider)
     {
     var vertices = new Vector3[8];
     List<float> XVertices = new List<float>();
     List<float> YVertices = new List<float>();
     
     var thisMatrix = collider.transform.localToWorldMatrix;
     var extents = collider.bounds.extents;
     vertices[0] = thisMatrix.MultiplyPoint3x4(extents);
     vertices[1] = thisMatrix.MultiplyPoint3x4(new Vector3(-extents.x, extents.y, extents.z));
     vertices[2] = thisMatrix.MultiplyPoint3x4(new Vector3(extents.x, extents.y, -extents.z));
     vertices[3] = thisMatrix.MultiplyPoint3x4(new Vector3(-extents.x, extents.y, -extents.z));
     vertices[4] = thisMatrix.MultiplyPoint3x4(new Vector3(extents.x, -extents.y, extents.z));
     vertices[5] = thisMatrix.MultiplyPoint3x4(new Vector3(-extents.x, -extents.y, extents.z));
     vertices[6] = thisMatrix.MultiplyPoint3x4(new Vector3(extents.x, -extents.y, -extents.z));
     vertices[7] = thisMatrix.MultiplyPoint3x4(-extents);
     foreach (var vector3 in vertices)
     {
         XVertices.Add(Camera.main.WorldToScreenPoint(vector3).x);
     }
     foreach (var vector3 in vertices)
     {
         YVertices.Add(Camera.main.WorldToScreenPoint(vector3).y);
     }
     
     var a = XVertices.Min();
     var aa = XVertices.Max();
     var b = YVertices.Min();
     var bb = YVertices.Max();
     return new float[] {a, aa, b, bb};
     }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
3d Text how do you autofit to a fixed space 0 Answers
collider bounds intersect but than for a UI button element 0 Answers
Problem with checking for intersection between two rotated objects 3 Answers
Collider2d.bounds.Intersects not detecting intersection 1 Answer
Why this script not working? 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                