Jump to content

[Plugin Request] "Real Altitude" altimeter that shows "when am I gonna crash?"!


Would you like a "Real Altitude" altimeter?...that shows "when you are gonna crash&qu  

8 members have voted

  1. 1. Would you like a "Real Altitude" altimeter?...that shows "when you are gonna crash&qu

    • Yes, please!...why does the default altimeter NOT do this?
    • No, I like crashing!...when I think I'm really high up!


Recommended Posts

Okay, I've got the raycast thing working.

On both pictures, note the ground cutting off the thrust plume.

http://members.shaw.ca/diazo/LandingHeight.jpg

http://members.shaw.ca/diazo/LandingHeight2.jpg

Note that I think the altimeter cuts off the decimal places and does not round them, so 0.9m shows as 0m, not 1m.

D.

Even though it takes doubles, it casts them to an int before setting the tumbler.

P.S. Good job.

Does it just cast straight down or do you use the vessel's velocity vector at all? (to check its flight path for trouble)

Edited by Starwaster
Link to comment
Share on other sites

It looks like the UI.setAlt command expects a double so I stuck a Math.Round in front instead of casting to int.

There is no trajectory checking. The distance is the shortest distance from any part on the vessel to ground straight down. This does include slopes however, so assuming a flat bottomed vessel landing on a hill, the distance shown will be from the corner of the vessel that is above the highest point on the hill that is below the vessel.

D.

Link to comment
Share on other sites

For each part on the vessel with physical significance, the closest point on the collider mesh to ground casts a ray to ground and the part with the shortest distance to ground gets displayed as the vessel altitude. See my second picture with the titled ship, the altitude being displayed is the bottom of the engine almost touching the ground.

I think you should include physically insignificant parts as well, otherwise parts like girders and beams that could be used as landing legs won't be considered

Link to comment
Share on other sites

Wait, what? I thought those were physically significant because they have a collision mesh.

It is stuff like struts that are physically insignificant because they can't collide with things.

Will check.

D.

Link to comment
Share on other sites

Wait, what? I thought those were physically significant because they have a collision mesh.

It is stuff like struts that are physically insignificant because they can't collide with things.

It seems you're right. I could have sworn truss pieces and the like weren't physically significant a version or two ago, but now the only parts that are insignificant in a stock game are the fuel line and the strut. My mistake

Link to comment
Share on other sites

However, a mod maker could still set a part's physicalSignificance to false and it would still collide with the ground.

Changed that check to use part.collider.enabled as that will be true if Unity will collide that part with the ground. (line 40 in the Git).

If part.collider.enabled is false, that means that part has no collider, or its collider is disabled, and either way that part will not collide with the ground.

D.

Link to comment
Share on other sites

Okay, I've got the raycast thing working.

Looking good! With the ocean issue, for better mod compatibility you can use CelestialBody.ocean instead of checking CelestialBody.bodyName.

It seems you're right. I could have sworn truss pieces and the like weren't physically significant a version or two ago, but now the only parts that are insignificant in a stock game are the fuel line and the strut. My mistake

That was actually a bug that was fixed sometime around 0.23. Some parts like the micro strut cube were using Unity PhysX instead of KSP physics. It was the leading cause of spontaneous station detonation.

Link to comment
Share on other sites

Okay, I've got the raycast thing working.

...can you add code to "draw a line" where the ray is casting?...for debugging, so while playing, we can SEE which point is being used as the raycast point? I think it would be fun to see & help in debugging.

I know about Debug.DrawLine() & Debug.DrawRay()...but they both say...

If gizmo drawing is enabled in the game view, the line will also be drawn there.

...I actually do know what this means: in the Unity editor there is a "Gizmos" button, if that button is clicked (toggled down/enabled), then gizmo drawing is enabled. However, the problem is that I don't have KSP open in the Unity editor (& I don't think I can do that)...so I don't know if gizmo drawing is enabled in KSP (I don't think so) & I don't know how to enable it (or if I can).

So, unless I can get gizmo drawing to be enabled in KSP, both of those functions are useless.

From the Ceko Labs Rangefinder mod's code, I know about LineRenderer...but have not actually tested it yet in my own code.

Link to comment
Share on other sites

I've never been able to get drawing a line to work, the way I tested this is I had a print(altitude | altitudeAboveTerrain | rayCastAltitude) scrolling in the debug window every Update() so I could see what was happening.

Also, thank you pizza for the CelestialBody.ocean location, I've been looking everywhere for that. Well, everywhere in the flightglobals and vessel classes anyway thinking it was a "is the vessel above an ocean?" check. I could not find it hence the check I did on body name.

Will change that to just checking the .ocean property.

Also, I need to add a range check. Right now there is no limit on the distance the ray can return, so if there's no pqs object below your vessel for some reason, the ray will return your altitude as the distance to the pqs layer on the other side of the planet. It will simply be a check that the distance returned by the ray is less then vessel.altitude + celestialBody.radius, and if the ray is greater, return vessel.altitude instead. If this is happening it means there is no pqs layer for your vessel to land on, so altitude above terrain makes no sense.

D.

Link to comment
Share on other sites

From the Ceko Labs Rangefinder mod's code, I know about LineRenderer...but have not actually tested it yet in my own code.
I've never been able to get drawing a line to work, the way I tested this is I had a print(altitude | altitudeAboveTerrain | rayCastAltitude) scrolling in the debug window every Update() so I could see what was happening.

LineRenderer is the most common way of doing this in KSP. There's an example here that has fixes for some of the common issues you'll see when trying to use it for the first time (line attached to the launchpad, detaching from the ship etc.).

Also, I need to add a range check. Right now there is no limit on the distance the ray can return, so if there's no pqs object below your vessel for some reason, the ray will return your altitude as the distance to the pqs layer on the other side of the planet. It will simply be a check that the distance returned by the ray is less then vessel.altitude + celestialBody.radius, and if the ray is greater, return vessel.altitude instead. If this is happening it means there is no pqs layer for your vessel to land on, so altitude above terrain makes no sense.

It may be more efficient to set the distance parameter for the ray itself. Instead of Mathf.Infinity, you could use the planet's radius plus the PQS draw distance (~2500m?).

Link to comment
Share on other sites

Okay, updated my code and updated the .dll download.

dll download (same link as previous)

Notable changes are:

Now use the celestialBody.ocean bool to check if a planet has oceans instead of by .bodyName string.

To clarify the vessel situation, if a vessel is in flight it will never display 0m altitude, it will only display 0m once a piece of the ship touches the ground (or water). Even if the ship is only 0.01m off the ground, it will display 1m. To me this this makes it clear what is happening. Altimeter is 0m? Vessel is touching the ground. Altitude 1m (or more?) Vessel not touching the ground.

Added a raycast limiter so that on high part ships, only the lowest parts emit the raycast to save processing power. I did not do any performance profiling on this, but I am assuming that running a sort on a list of parts is much less demanding then emitting a raycast from each part.

Added distance limit to raycast so it can't hit the terrain on the far side of the planet you are landing on.

D.

Edited by Diazo
Link to comment
Share on other sites

Okay, I've gone ahead and made this an official release that can be found here.

I've talked to FORUM_TEST_2-19-14 he is going to release a fancier mod with all the bells and whistles that incorporates my code, but this is something I wanted to get out there for people to see on it's own.

No changes made for this release, it is the same as the download link in my previous post.

D.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...