Jump to content

Tutorial for a basic Landing Leg


Recommended Posts

Landing gear and wheels are not easy and even though there is quite some information spread across the forum it took me very long to get working results. One thing I really missed was a step-by-step tutorial that tells me what is required, where stuff needs to be placed and so on. A couple of days ago, I had successfully created my first working landing leg. It's very simple with just a suspension and rotateable foot but it works! Now I wanna try to write down a step-by-step tutorial on how to create the most basic landing legs. I also hope to get some feedback to improve my assembly of landing legs and/or this tutorial.

Software:
- Blender (v2.79)
- Gimp (v2.8.22)
- Unity (5.4.0p4)
- Part Tools
- NotePad/NotePad++

1. Blender
The Blender part is rather easy just make sure to build the retracted version. Create the objects as shown in the picture and drag them in the correct hirearchy. What I found to be important is that the center of foot-hinge is at 0,0,0 and the model is build around it.  All objects should have their origin at 0,0,0, rotation 0,0,0 and scale 1,1,1.

Spoiler

pdoQBcs.png

2. Unity
1.) Start with a New Scene and delete everything in it. "Create Empty" (Ctrl+Shift+N) and set position to 0,0,0.
2.) Make sure the Layers are set up correctly in unity. The following are required: Layer26: WheelCollidersIgnore, Layer27: wheelColliders, Layer30: SurfaceFX. If the Layers aren't set up already, expand the Layers, click "Add Layer" and enter the Layer names at the corresponding User Layer.
3.) Add the Part Tools script and set up Model Name, URL and Texture Format.

Spoiler

nto8UCO.png


1.) Drag the TestLeg.blend file to the newly created GameObject (I use the .blend file directly with .fbx conversion done in the background)
2.) Select "ExampleLandingLeg" and remove the Animator Component (right click / Remove Component).

Spoiler

CIqrvfL.png


1.) Create an Empty, rename it to "wheelCollider" and drag it as child of "GameObject".
2.) Create an Empty, rename it to "deployTgt"" and drag it as child of "ChassisBlue".
3.) Make sure their position is 0,0,0.

Spoiler

Of4RwJl.png

 

Now all objects except the PistonCollider (comes later) are present and they can be configured. Start with the deploy animation.
1.) Select "ExampleLandingLeg".
2.) Hit "Add Component / Miscellaneous / Animation" (Note that AnimatoR and AnimatioN are two different things!).
3.) Click " Window / Animation" (or Ctrl + 6).

Spoiler

y0zI5id.png


The Animation Window pops up. Click "Create" and enter a name like "deployLegAnim".
1.) Click "Add Property" and navigate to "ChassisBlue / PistonRed / Transform".
2.) Add the "Position" entry by hitting the small +.
3.) Change to CurveView.

Spoiler

5krmA7g.png


1.) Go to Frame 60.
2.) Set Z position to -2 (suspension-distance).
3.) Animation is done, close the Animation window.

Spoiler

pTkN93v.png


1.) Select "ChassisCollider".
2.) Remove the MeshRenderer Component (right click / Remove Component).
3.) Hit "Add Component / Physics / MeshCollider" and check the "Convex" box.
4.) Set layer to "WheelCollidersIgnore" (26).

Spoiler

WJaieDQ.png


1.) Select "wheelCollider".
2.) Hit "Add Component / Physics / Wheel Collider" and configure it as shown in the picture (non-default values are marked red).
Mass: IDK, just works
Radius: The distance from hinge-origin (0,0,0) to the lowest point of the foot (while retracted)
Suspension Distance: As the name says (should be the same distance covered by the animation)
Spring: Springhardness
Damper: IDK, just works
Target Position: Default suspension position. 1 is fully deployed (landing gear), 0.5 is half deployed (wheels).
3.) Set Layer to "wheelColliders" (27).

Spoiler

En4dYS3.png


There is one last step but I highly recommend to save the unity scene at this point and exported/test the model. Once the PistonCollider is added, it becomes much harder to verify that the wheelCollider is in the right position (in KSP).

Spoiler

2UeJD4M.png


Switch to a filebrowser and navigate to the GameData folder of the KSP installation. Create a new folder "ExampleLandingLeg" and copy modelELL.mu and the texture in that folder. Also Create or copy a new config file in that folder and paste the following (the config already references "PistonCollider" which is not yet included but don't worry):
 

PART
{
	// General parameters
	name = ExampleLandingLeg
	module = Part
	author = YourName

	// Asset parameters
	mesh = TestLeg.mu
	scale = 1
	rescaleFactor = 1

	// Node definitions - Position X, Position Y, Position Z, Up X, Up Y, Up Z
	node_attach = 0.0, 1.5, -0.19, 0.0, 0.0, 1.0, 1

	// Editor parameters
	TechRequired = advLanding
	entryCost = 1
	cost = 1
	category = Utility
	subcategory = 0
	title = ExampleLandingLeg
	manufacturer = None
	description = Soon TM
	tags = example landing leg

	// attachment rules: stack, srfAttach, allowStack, allowSrfAttach, allowCollision
	attachRules = 0,1,0,0,0

	// Standard part parameters
	mass = 1.0
	bulkheadProfiles = srf

	// Drag
	dragModelType = default
	maximum_drag = 0.2
	minimum_drag = 0.2
	angularDrag = 2

	// Damage and Temperature
	crashTolerance = 40
	maxTemp = 2200

	// Resources

	// Modules
	MODULE
	{
		name = ModuleWheelBase
		wheelColliderTransformName = wheelCollider		// object with WheelCollider-Component
		wheelType = LEG
		FitWheelColliderToMesh = False				// setting this to true will override the radius and center parameters
		radius = 0.1						// Same as set in unity
		center = 0,0,0						// Same as set in unity
		mass = 0.05						// Same as set in unity
		autoFrictionAvailable = False
		clipObject = PistonCollider				// Moving Collider for the piston. Causes trouble if not set.
		TooltipTitle = none
		TooltipPrimaryField = 
		groundHeightOffset = 4
	}
	MODULE
	{
		name = ModuleWheelSuspension
		baseModuleIndex = 0					// Reference to the location of "ModuleWheelBase" in the config (first module is 0)
		suspensionTransformName = PistonRed			// object (and children) that will be moved by suspension
		suspensionColliderName = PistonCollider			// Moving Collider for the piston. Causes trouble with the wheelCollider if not configured
		suspensionDistance = 2					// Same as set in unity
		suspensionOffset = 0					// IDK. There is some interaction with the position of deployTgt in unity
		targetPosition = 1					// Same as set in unity; With no force applied the suspension will be fully deployed
		springRatio = 20					// Same as set in unity; Springhardness
		damperRatio = 1						// Same as set in unity
	}
	MODULE
	{
		name = ModuleWheelDeployment
		baseModuleIndex = 0					// Reference to the location of "ModuleWheelBase" in the config (first module is 0).
		animationTrfName = ExampleLandingLeg			// object with Animation Component (not the animated object!)
		animationStateName = deployLegAnim			// name of the animation
		deployedPosition = 1
		deployTargetTransformName = deployTgt			// object that will become the wheelCollider when deployed
		TsubSys = 1						// When will wheelCollider switch during the animation. 1=end, 0=start
	}
	MODULE
	{
		name = ModuleWheelLock
		maxTorque = 500
	}
	MODULE
	{
		name = ModuleWheelBogey
		baseModuleIndex = 0					// Reference to the location of "ModuleWheelBase" in the config (first module is 0)
		bogeyTransformName = FootYellow				// Object that will act as foot
		deployModuleIndex = 2					// Reference to the location of "ModuleWheelDeployment" in the config (third module is 2)
		maxPitch = 160						// Degree. Maximum positiv deflection
		minPitch = -160						// Degree. Maximum negative deflection
		restPitch = 0						// Degree. Position with no influences
		pitchResponse = 100
		bogeyAxis = 1, 0, 0					// Axis to rotate around
		bogeyUpAxis = 0, 0, 1					// Axis pointing upward. Can be 0, 1 or -1
	}
}

Save the config and fire up KSP. Choose a Pod, add four legs around it and launch vessel (it may jump a bit at first, use launchclamps to avoid). If everthing went well, the foot should be exactly level with the ground and the suspension should work as well. Hit Alt + F12 to bring up the cheatmenu and play a bit with the gravity to see if everthing is alright. Hit "g" to retract the landing gear and deploy it afterwards again. The piston will go in the ground and the vessel jumps high at the end of deployment. So the PistonCollider needs to be set up to avoid this. Close or minimize KSP and go back to unity.

The PistonCollider:
1.) Create another empty GameObject, name it "PistonCollider", make sure it is at 0,0,0 and set it as child of "PistonRed"
2.) Add Component "Physics / CapsuleCollider" and configure it as shown. The lower end should match the center of the wheelcollider (0,0,0)
3.) Set Layer to "SurfaceFX" (30)

Spoiler

KKkycGW.png


Re-export the model, fire up KSP or Reload the Database and test the deploy mechanic. Done!

imgur album

My sincere thanks to the people on the forum who shared their experience and knowledge about landing legs and wheels!
EmbersArc for the cheat-sheet
NecroBones and nli2work for the information provided in the Landing Legs 1.1 thread
SpannerMonkey(smce) for information provided in the most basic wheel thread
blackheart612 for the guide to making Deployable Landing Gears
Nils266 for the "LandingLeg2" part from PlanetaryBaseSystems, it was a very usefull example.
Nifty255 and linuxgurugamer for Kerbal Object Inspector Continued

 

Link to comment
Share on other sites

@blackheart612 Thank you very much :)

Some more Landing Leg stuff:

After the basic landig leg I've tried to achive some more complex builds. Especially the second example took me lot of time to figure out. I won't explain them as detailed as before but hopefully enough to rebuild them. I save the blend file under a different name and start with a new unity scene for each example. Also the animation names change, so you may need to adapt the config ("animationTrfName" and "animationStateName" in ModuleWheelDeployment).

1.) Position
This example extends the whole leg 1 m to the side before deploying the piston and it also uses constraints (Pneuma objects). The hierarchy has changed a little and therefor all new or moved objects are marked in blender. The ChassisCollider is now a child of ChassisBlue, the rest is new. The Pneuma objects have the origin at their individual hinge points and PneumaHullRed is 180° rotated around the x-axis to make Z+ face down.

Spoiler

TDYTUHk.png

The unity setup is pretty much the same as before. StaticCollider must be set up and the animation needs some new keys for the sideway-movement.

Spoiler

MBePdDR.png

Config also stays the same, just the constraints need a new module:

	MODULE
	{
		name = FXModuleLookAtConstraint            
		CONSTRAINLOOKFX
		{
			targetName = PneumaStickYellow
			rotatorsName = PneumaHullRed
		}
		CONSTRAINLOOKFX
		{
			targetName = PneumaHullRed
			rotatorsName = PneumaStickYellow
		}
	}

Now check the wheelCollider position in KSP. I usually set gravity to 0.04 and move the vessel to the side on the launchpad until it drops down:

Spoiler

1CLP4sN.png

The constraints work as well.

 

2. Rotation
This example rotates the leg by 30° before deploying the piston and this is where it gets messy. First I'll explain my unsuccessfull attempt and show the problem that arises:
The blender setup is the same as the example above just the origin of ChassisBlue has been set to the hinge-point. All children except the PneumaStickYellow still have their origin at 0,0,0 (global coordinates).

Spoiler

fBbeoZr.png

Unity setup is again the same, just the animation needs rotate keys instead of position.

Spoiler

FRDcBSf.png

Config is also the same again.

When I verify the position of the wheelCollider, it is off. First thing I noticed is a minimal vertical offset but the main problem is the horizontal offset. For hours I've tried everything I could come up with but the result is always the same (or a broken model).

Spoiler

5vuEa4E.jpg


My thoughts on deployTgt mechanic:
When the leg deploys in KSP, the animation is played and at a given point during this animation (TsubSys key in ModuleWheelDeployment), the suspension-object and all children are "moved" to the location of deployTgt. The (local) position of the suspension-object and children is identical to their position on the last frame of the animation. Y+ of the deployTgt also sets the axis for the suspension. The suspensionOffset in ModuleWheelSuspension is an offset for the "moved" suspension-object along the Y axis of deployTgt. What I don't know/understand is how the wheelCollider gets its offset from deployTgt position. So currently my best guess is that the wheelCollider is not lowered along the Y-axis of deployTgt but instead along the global Y-axis.

I was about to write this down up to this point and ask for help when I realized that the model could be rotated by 30° in retracted state. This way the suspension is always along the global Y axis. The model would need to be rotated manually in the config file later. A quick look at the stock legs revealed that the models are rotated:

...
	node_attach = 0.0, 0.0, 0.0, 0.0, 0.3756781, 0.9267502
...
// From landingLeg1

The solution
1.) In blender set the cursor to the hinge-point of ChassisBlue
2.) Make sure pivot point is 3D cursor
3.) Select ChassisBlue and PneumaHullRed and rotate them 30° around the X axis.

Spoiler

wLbxblN.png

Save and go to unity. Some of the animation keys need to be set up again but everything else should be fine. Export the model and open the config.
Now a direction vector is required that is perpendicular to the flat sides of StaticGray. It needs to be parallel to the green arrow in the picture above (the one on the textured model). 0.0, 0.5, 1.0 is such a vector and the config should look like this

	node_attach = 0.0, 2.4384, -0.26651, 0.0, 0.5, 1.0, 1

Another thing I forgot to mention in the tutorial is Center of Mass Offset. It should be set to move it away from the foot.

	CoMOffset = 0.0, 2.4, 0.0

Fire up KSP and verify that the wheelCollider is in place now

Spoiler

glpii6d.png

Done! The attachment of the legs to the capsule is a bit off but it should be easy to fix with some trial and error on the attach node.

I will add the additions to OP after I did dome more experiments with legs (and maybe wheels ?!).

 

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