Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

how do i get the points on a gamobject collider when it rotating ?

Discussion in 'Editor & General Support' started by TheDodgerUk1, Oct 23, 2019.

  1. TheDodgerUk1

    TheDodgerUk1

    Joined:
    Dec 3, 2013
    Posts:
    61
    Code (CSharp):
    1.     boundPoint1 = collider.bounds.min;
    2.      boundPoint2 = collider.bounds.max;
    3.      boundPoint3 = Vector3(boundPoint1.x, boundPoint1.y, boundPoint2.z);
    4.      boundPoint4 = Vector3(boundPoint1.x, boundPoint2.y, boundPoint1.z);
    5.      boundPoint5 = Vector3(boundPoint2.x, boundPoint1.y, boundPoint1.z);
    6.      boundPoint6 = Vector3(boundPoint1.x, boundPoint2.y, boundPoint2.z);
    7.      boundPoint7 = Vector3(boundPoint2.x, boundPoint1.y, boundPoint2.z);
    8.      boundPoint8 = Vector3(boundPoint2.x, boundPoint2.y, boundPoint1.z);
    i tried this , but it does not compensate for when the gameobject is rotating
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Unity's bounds are axis aligned bounding boxes (AABB) so they are not rotating. They should be used to get the approximate position/volume of the object. You need to calculate the rotation yourself.

    It would help if I knew what you are trying to do.

    But if you need the rotated points of that collider/bounding box, one simple way would be to capture the mesh bounds from the unrotated object, then get the extents of the object as points (like you have now).

    Now that you have the points, you can use a matrix to rotate the points or I think easier way would be to use TransformPoint to translate those points so that they take into account the object rotation.
     
  3. Elharter

    Elharter

    Joined:
    Sep 20, 2015
    Posts:
    58
    Ive got exactly the same problem....
    upload_2021-2-10_0-24-29.png

    I need the 4 points of the boxcollider corners, but it doesnt work because of rotation.