Jump to content

Raycasting to the water's surface as well as terrain?


Recommended Posts

There's a bug in @charfa's otherwise-excellent update to @XanderTek's Landertrons mod that I had thought would be an easy fix, but is not proving so simple to overcome.

Landertrons are solid-rocket motors which can be set to automatically execute a suicide burn to land a spacecraft.  They get the distance to terrain (in the direction of the landertrons' thrust vectors) by raycasting to layer 15 (i.e. using 1 << 15 for a layer mask).  This doesn't work over water, because the "terrain" is several hundred meters below the surface, so the landertrons don't get the correct distance. I had thought it would be easy enough to fix by adding layer 4 to the mask as well (i.e. layerMask = (1 << 4) | (1 << 15);), but it doesn't work -- the landertrons still only see the terrain below the water.  Is the surface of the water on some other layer, or is this going to require some kind of workaround like Kerbal Foundries does (spawning a collider underwater to give their repulsors something to push against)?

Link to comment
Share on other sites

Water surface is always at 0m altitude unless Kopernicus has changed things (changed as in made that not a given. I would assume not). Because the ocean sphere will show up in any land below 0m, you can report the distance to 0m for any planet with an ocean

rayCastResult = ....;

if (vessel.mainBody.ocean)
  raycastResult = Min(vessel.Altitude, rayCastResult);

 

Edited by Crzyrndm
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...