Snark Posted December 5, 2015 Share Posted December 5, 2015 (edited) I'm working on a mod where I'd like to know how much ground clearance the ship has, i.e. height above ground level of the lowest point on the ship in its current orientation. It's easy to get the height of the control-from-here point, but that's unhelpful for me. I don't need it to be accurate to the centimeter, so I'm willing to settle for a reasonable approximation if it will significantly simplify the code. Does anyone have any suggestions for recommended approach? For example, is there some simple way to get a 3D bounding box for a part, so that I could just iterate through all the parts on the ship to find the lowest extent of a bounding box? Or is there some simple method I'm missing? Any advice much appreciated. Edited December 5, 2015 by Snark Link to comment Share on other sites More sharing options...
satnet Posted December 5, 2015 Share Posted December 5, 2015 There is "collider.bounds" on the Part. I believe that will give you want you want. You might also look at "collider.ClosestPointOnBounds". Link to comment Share on other sites More sharing options...
Boris-Barboris Posted December 5, 2015 Share Posted December 5, 2015 On the first thought: Very cpu-intensive task, be careful. Part has "collider" public field, Collider class has a box http://docs.unity3d.com/ScriptReference/Collider-bounds.html Box is in world space, find the closest vertex to the planet center (can be done by http://docs.unity3d.com/ScriptReference/Bounds.ClosestPoint.html with planet position as input). Use vessel.mainbody.pqscontroller.getSurfaceHeight(), it gives offset of pqs terrain from sea level at passed surface normal vector (can be produced by this.mainBody.GetRelSurfaceNVector() from latitude and longitude of box vertex). If I was in your pants, i would disable this peace of code on vessel.heightFromTerrain > 200.0f, also I would sort parts by the distance between planet and part.transform every 10-20 physical frames, then have three caches: previously found closest to terrain part. 4-5 parts from the start of sorted part list, wich you will check each frame too. 4-5 random parts from sorted part list, reshuffle them on large angular excitations of vessel.referenceTransform, and each couple of frames. Don't recalculate each frame. Link to comment Share on other sites More sharing options...
Stone Blue Posted December 5, 2015 Share Posted December 5, 2015 (edited) IIRC, Diazo's Landing Height mod does just that... Maybe give him a shout-out, and ask him about it, or pop the hood on the mod, and see if you can figure out how he does it?http://forum.kerbalspaceprogram.com/index.php?/topic/69127 Edited December 5, 2015 by Stone Blue Link to comment Share on other sites More sharing options...
Snark Posted December 5, 2015 Author Share Posted December 5, 2015 (edited) Excellent, thanks for all the suggestions everyone! That gives me plenty of avenues to explore. My problem was simply that I had no idea where to begin. Excellent point about CPU intensiveness, and I really don't need something super-fancy. It may be as simple as, for example, caching the lowest point relative to control-from point and then only updating it a couple of times per second. I've got a pretty low bar, here-- I'm not aiming for "perfect". All I need is "not laughably bad." I'll crack the lid on @Diazo's mod, thanks for pointing it out. He does good stuff and has already been personally helpful to me when I was sorting out a different problem. Diazo is good people. (Now if I could just figure out how to track crew assignments in the ship editor...) Edited December 5, 2015 by Snark Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now