Jump to content

How to get highest point on a vessel?


Recommended Posts

I'm trying to get the highest point on a vessel, in relation to the planet.  Would also be useful to find the horizontal distance from a Transform (found in a part).  I thought I could do it with Vessel.vesselSize, but that's just a raw set of numbers, no way (AFAIK) to know the orientation of the vessel.

Thanks in advance

 

Link to comment
Share on other sites

It was one I had looked at.  Unfortunately, it uses this:

 

                    Vector3 partEdge = p.collider.ClosestPointOnBounds(FlightGlobals.currentMainBody.position); //find collider edge closest to ground
 

which is a Unity call, and gets the closest point to the body.  I would need the furthest point, and there is no unity call for that

But, it gave me an idea, I just found some code to get the furthest point.  

Link to comment
Share on other sites

  • 2 months later...

I realized I never posted.  Here is the code to find the furthest point:

       // Following method from Unity forum:
        // https://forum.unity.com/threads/how-to-find-a-point-in-a-collider-farthest-from-a-given-position-reversed-closestpointonbounds.344122/

        Vector3 GetFurthestPointOnBounds(Collider boxCollider, Vector3d myVector)
        {
            List<Vector3> vertexPoints = new List<Vector3>();

            //BoxCollider boxCollider = gameObject.GetComponent<BoxCollider>();

            vertexPoints.Add(boxCollider.bounds.max);
            vertexPoints.Add(boxCollider.bounds.min);
            vertexPoints.Add(new Vector3(boxCollider.bounds.max.x, boxCollider.bounds.max.y, boxCollider.bounds.min.z));
            vertexPoints.Add(new Vector3(boxCollider.bounds.max.x, boxCollider.bounds.min.y, boxCollider.bounds.min.z));
            vertexPoints.Add(new Vector3(boxCollider.bounds.max.x, boxCollider.bounds.min.y, boxCollider.bounds.max.z));
            vertexPoints.Add(new Vector3(boxCollider.bounds.min.x, boxCollider.bounds.min.y, boxCollider.bounds.max.z));
            vertexPoints.Add(new Vector3(boxCollider.bounds.min.x, boxCollider.bounds.max.y, boxCollider.bounds.max.z));
            vertexPoints.Add(new Vector3(boxCollider.bounds.min.x, boxCollider.bounds.max.y, boxCollider.bounds.min.z));


            int maxDistanceVector = 0;
            float distance = 0;
            Vector3 getCollisionPoint = boxCollider.ClosestPointOnBounds(myVector);

            for (int i = 0; i < vertexPoints.Count; i++)
            {
                if (i == 0)
                {
                    distance = Vector3.Distance(getCollisionPoint, vertexPoints[i]);
                    maxDistanceVector = 0;
                }
                else
                {
                    float newDistance = Vector3.Distance(getCollisionPoint, vertexPoints[i]);
                    if (distance < newDistance)
                    {
                        distance = newDistance;
                        maxDistanceVector = i;
                    }
                }

            }

            //Debug.Log("Farest away point of box collider from vector: " + vertexPoints[maxDistanceVector]);
            return vertexPoints[maxDistanceVector];
        }

 

Edited by linuxgurugamer
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...