Jump to content

Determine ships orientation relative to flight path


Recommended Posts

I am looking for a way to measure angle of attack, angle of yaw and angle of side slip all relative to the ships flight path vector. So far, I've found almost nothing on the flight path vector. Also, angle of roll relative to the planet's surface would be nice too.

Thanks

Link to comment
Share on other sites

It is not that simple unfortunately.

I'm going to point you at the source code for either MechJeb or kOS which I assume does that so you can take a look.

It is what I did when I needed to get a vessel's angle off vertical for my velocity mod, ended up looking at mechjeb to walk me through the quanterion's to get the information needed.

D.

Link to comment
Share on other sites

The reason it's hard to find is that it's technically NOT part of the KSP API.

It's part of the Unity API.

First, ask KSP for the vessel's Transform (i.e. GetTransform() or ReferenceTransform(), I don't remember which).

Then you can ask Unity for the data about that Transform:

http://docs.unity3d.com/ScriptReference/Transform.html

BUT, and this is the mess, it will be the transform relative to the worldspace KSP creates which is not rotated to match the planet surface at all.

So the next thing you have to do is work out the transform of the SOI body you are around, and work out that relative to to your rotation.

You can do that with Vessel.srfRelRotation. It gives you a quaternion of the surface rotation where your vessel is - by comparing that to your vessel's rotation you can get the data you're looking for if you delve into the Unity API for how to do that.

Edited by Steven Mading
Link to comment
Share on other sites

I'll give that a try. But first, I'll need to do some research on vector math with quaternions.

Thanks,

EDIT: I'm having a really hard time figuring out which way vectors are pointing. Is there any debug option to draw a vector?

Edited by wizzlebippi
Link to comment
Share on other sites

  • 2 weeks later...

Use the unity primitive called LineRenderer to draw a line.


GameObject lineObj = new GameObject("laser line");
bool isOnMap = MapView.MapIsEnabled;
lineObj.layer = isOnMap ? 10 : 1; // 10 is the map layer, 1 is the transparent effect on flight cam layer.

LineRenderer line = lineObj.AddComponent<LineRenderer>();

line.material = new Material(Shader.Find("Particles/Additive") ); // generic flat texture
Color c1 = new Color( 1.0f,0.0f,0.0f,0.5f); // red, semi-transparent.
Color c2 = new Color( 1.0f,1.0f,0.0f,0.2f); // yellow, even more transparent.
line.SetColors( c1, c2 ); // color of start/end of line drawing - Unity will make a fade effect between the two colors
line.SetVertexCount(2); // Despite the name, LineRenderer actually renders a path of lines, not a single line, so to just render one segment limit it to 2 vertices.
line.SetWidth( 0.5f, 0.5f ); // width of start/end of line. might need it wider on map view.
line.SetPosition( 0, __put_some_poistion_vector_here___) ; // start point
line.SetPosition( 1, __put_some_poistion_vector_here___) ; // end point
line.enabled = true; // line is invisible until you do this.

Link to comment
Share on other sites

Above a certain altitude, the game switches modes from:

- Planet stays fixed in space, and the universe rotates around it.

to

- Planet rotates in space, and the universe stays still.

At low altitudes it keeps the planet stationary so that the terrain polygons don't have to be constantly repositioned as the planet rotates, which would lag animation to a standstill.

So I suspect you might be seeing something happen at the transition between those two modes, but it's hard to tell for sure.

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