Jump to content

Where is altitude


Recommended Posts

I am making my first plugin. If I wanted to set something in an IF Then statement based off of how far from ground I am, what class would that be in?

also where would i find current state of landing gears (true false).

edit--

ok i found vessel.altitude and height from ground.

they seem to work fine for what im doing. i still need to find where landing gear state is located.

Edited by polimerjones
Link to comment
Share on other sites

Those two things work poorly or do not work for what you intend them to. Altitude will always give you your sea level altitude, and height from ground in vessel doesn't work very welll. There's currently no easy way to find the height from the surface. I suggest two things:

public Vector3 CoM;
public vector3 up;
public float ASL;
public RayCastHit craft;

CoM = this.vessel.findWolrdCenterOfMass();
up = FlightGlobals.getUpAxis(CoM);
ASL = FlightGlobals.getAltitudeAtPos(CoM);

public float TrueAlt()
{
if (Physics.Raycast(CoM, -up, out craft, ASL + 1000, 1 << 15)
{
return Mathf.Min(craft.distance, ASL);
}
else
{
return ASL;
}
}

That's one way to do it. EachTime you would call TrueAlt(), it would give you true altitude from the ground or water. This will work even on unfocused vessels in physics range. The other would be this I think:

public vector3 CoM;
public float ASL;
public float trueAlt;

CoM = this.vesse.findWorldCenterOfMass();
ASL = FlightGlobals.findAltitudeAtPos(CoM);

trueAlt = Mathf.Min(ASL - this.vessel.pqsAltitude, ASL);

This one should also work, but I'm not sure if it will also work on unfocused vessels. Personally I'd go with the first one.

To find the landing gear it's a whole new story however. You'll need a foreach loop that scans for all the parts in the vessel and identifies which ones are landing gear I think.

Link to comment
Share on other sites

thanks for the help. but going back to the gear issue. I dont really need to know how many landing gears the ship has just if the light on the top is on or off. (or should the gear be up or down)

also any tips for speed dampening would be awesome.

Edited by polimerjones
Link to comment
Share on other sites

Landing gears (or rather, the action group that in most cases controls all gears at once, so you don't know how many of them are there) are accessible through

FlightGlobals.ActiveVessel.ActionGroups.groups[baseAction.GetGroupIndex(KSPActionGroup.Gear)]

It's a bool, reading it gets you the state of gear toggle, setting it changes the state and moves the gears.

Link to comment
Share on other sites

thanks. i will try that out.

edit---

just had a chance to try that out Mihara and it worked perfectly on the first try. Many thanks.

Now the last thing I need to figure out is drag/dampening. Basically im looking to slow the ship down if it meets certain requirements.

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