Jump to content

[Solved] Is there a way for ModuleLiftingSurface to specify the vector for lift?


Recommended Posts

I'm working on my LES plugin code again.  It uses ModuleLiftingSurface to simulate the aerodynamic effects of its deployed canards.

ModuleLiftingSurface applies lift in the Z axis. This wasn't a big deal until I wanted to start adding details to the blast cover that align with the underlying CM.  But unfortunately, the lift vector is 90 degrees away from where it needs to be with how the command modules are oriented in the VAB.  Until now, I have rotated my part 90 degrees to get the lift vector correct for the LES, but that means that the user needs to rotate the LES 90 degrees to get it to line up correctly with their pods.

Is there a way via plugin code or config to specify the direction of the lift vector for ModuleLiftingSurface?

Edited by Kurld
Solve
Link to comment
Share on other sites

Currently it uses the part transform's forward (z) axis to apply lift.  It doesn't look like you can change the axis, but it looks like you can possibly change the transform it's looking at.  This might work:

public class MyLiftingSurface : ModuleLiftingSurface
{
	[KSPField]
	public string transformName;

	public override void OnStart(StartState state)
	{
		base.OnStart(state);

		if (!string.IsNullOrEmpty(transformName))
		{
			Transform testTransform = part.FindModelTransform(transformName);
			if (testTransform != null)
				baseTransform = testTransform;
			else
				Debug.LogError($"[{moduleName}] could not find transform named '{transformName}'");
		}
	}
}

Note that you don't have to set baseTransform in the case that transformName was null/empty or if the transform wasn't found because the base already sets this.

Also note that I haven't actually tested this (or worked much with this area of KSP) so it might not give the intended result.

Edited by blowfish
Link to comment
Share on other sites

I am happy to report that this does in fact work!

In my plugin code I added a class named ModulePebkacLiftingSurface and included the code provided by @blowfish pretty much as-is.

Then I added a child game object to the top-level "part tools" game object for my part in Unity editor and set its local rotation to be -90 degrees around the Y axis. This causes the blue arrow for that child to point in the direction of the expected lift. I named the child transform "PebkacLiftingSurfaceTransform" and then in the part config I added a node for the new module:

	MODULE
	{
		name = ModulePebkacLiftingSurface
		transformName = PebkacLiftingSurfaceTransform
		useInternalDragModel = false
		deflectionLiftCoeff = 0
	}

Finally, I rotated my model in Unity so that it is oriented as one would naturally expect it to line up with the command pod... the "front" of the LES now lines up with the front of the command pod, instead of being off by 90 degrees.

Now the user can simply drop the part in place: It is already oriented correctly, and finally, when the canards deploy, the pod rotates to retrograde as expected.

Thanks so much!

Link to comment
Share on other sites

  • 2 months later...
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...