Jump to content

[Solved]How to get altitude from specified transform


Recommended Posts

I want to figure out the altitude from one transform on the model but not the vessel center.

Following code didn't give a reasonable reading. I want to calculate the altitude beyond the sea so raycast can not help(Maybe?).

Any help will be appreciated.


Transform[] detectorTransform = part.FindModelTransforms(detector); //Get the transform position
vector3 relativeposition = detectorTransform.position - vessel.Transform.position; // calculate the distance between detector and vessel center
float height = vessel.altitude + relativeposition.y; //give out result

Edited by flywlyx
Link to comment
Share on other sites

The issue is that relativeposition.y has no relation to the body a vessel is above, rather it is probably straight up in World space co-ordinates that everything orbits in.

If you are in a roughly equatorial orbit, relativeposition.y will be roughly 'north' as relative to the body you are orbiting.

For what you want, I think there is a method you can call to get altitude directly, something like FlightGlobals.GetAltitude(Vector3) if I remember right.

D.

Link to comment
Share on other sites

I think you want a single transform, not an array.


Transform detectorTransform = part.FindModelTransform(detector); //FindModelTransform without the s
float height = mainBody.getAltitude(detectorTransform.position);

Link to comment
Share on other sites

The issue is that relativeposition.y has no relation to the body a vessel is above, rather it is probably straight up in World space co-ordinates that everything orbits in.

If you are in a roughly equatorial orbit, relativeposition.y will be roughly 'north' as relative to the body you are orbiting.

For what you want, I think there is a method you can call to get altitude directly, something like FlightGlobals.GetAltitude(Vector3) if I remember right.

D.

You are right, FlightGlobals.getAltitudeAtPos(Vector3) is more easier.

- - - Updated - - -

I think you want a single transform, not an array.


Transform detectorTransform = part.FindModelTransform(detector); //FindModelTransform without the s
float height = mainBody.getAltitude(detectorTransform.position);

I always make more silly mistake like thsi:blush:thank you

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...