Jump to content

[Tutorial] Animated Landing Leg w/ Suspension


BahamutoD

Recommended Posts

Animated Landing Leg w/ Suspension Tutorial

This is a quick tutorial for the unity setup of a landing leg with suspension.

Disclaimer: I won't be covering modelling or animation, just what you need to do to set it up in unity to get it to work properly in the game.

I assume you already know how to make a basic part. I am by no means an expert, but there's no info on how to set these up except for that one unity screenshot of the stock leg and there's a few things you need to do that you can't really tell from it. I just figured it out by combining info from that picture and the rover wheel picture, and a lot of guessing.

ingame.png

Lets get started. First model and animate your leg. I made this quick and ugly model in Blender for the sake of this tutorial.

Important: Make sure that the foot object's local Y axis is pointed down, and the X axis is pointing along it's hinge axis. This will be used by KSP to orient the foot to the ground.

blenderfoot.png

If you're modelling in Blender, you can set it to use metric units, which will make it follow the same units of measurement as KSP.

Export it as a .fbx file; make sure to check 'include animation'.

Import it to Unity. In the model tab, set the scale to 1 (it defaults at 0.1 for some reason) if you used the metric scale in Blender.

In the rig tab, set the animation type to Legacy.

In the animation tab, name the animation. I named mine "deploy".

animation.png

As usual, create a GameObject at 0, 0, 0.

Drag the model into the game object and setup the texture and whatnot.

Add a game object for the collider of the part of the leg that moves. I named the moving part "piston", and it's collider object "pistonCollider".

--If you did the animations in your 3D program, don't rename prefab objects in Unity or you will break the prefab animation.

Place the collider as a child of the moving piston object and set it's transform position to 0, 0, 0. This will place it at the origin of the piston object.

Add a collider component (I used a capsule collider). Adjust the dimensions and center of the collider component, not the object's transform. This will be the collider that collides with the ground. The foot itself will not have a collider.

You can see the setup here:

addlayer.png

At this point, lets add a couple layers. As you can see above, click on the layers drop-down and click "add layer".

Click on the empty area to the right of layer 26, and name it "WheelCollidersIgnore".

Do the same for layer 27, named "WheelColliders".

(as seen here: )

layers.png

Go back to the piston collider, and set it's layer to "WheelCollidersIgnore". (Set any collider that the wheel collider may pass through during its travel to this layer. Thanks, Tiberion).

Now, create a game object and name it "wheelCollider".

Place this in the same level of the heirarchy as the piston. (Not as a child of the piston.)

Set its layer to "WheelColliders".

wheelcollider.png

Set its transform position as the exact same position as the piston object. This is important! (Copy and paste the position values from the piston object to the wheel collider object)

Then, as you can see above, set it's center (not gameobject position) and rotation so that its at the top of the piston, and the green line coming from the center of the wheel (not the green axis, the green line) is pointing along the piston to where the foot is. (see above.)

Important: Set it's suspension distance long enough that it protrudes through where the bottom of the piston collider is. If its not long enough, then only the piston collider will touch the ground and you will have a rigid leg.

Also visible in the above picture is the module config. As you can see, I made it so the spring and damper values are the same between the config and unity; I don't know if it matters, but I did that just to be safe. You should adjust these to your liking as you test the part in game.

The config is pretty self explanatory except theres one error in that picture: set "alignFootUp = true", not false.

suspensionUpperLimit is the distance you want the suspension to travel. I set mine to half the distance as the suspension limit of the wheel collider, so it will only move half the distance at max compression.

Here's the overall setup. Make sure to uncheck Play Automatically on the animation component.

finalsetup.png

I know, I'm bad at explaining things, but you can look at all my files here:

Download Part, Blender, Unity files.

If you have any questions, please ask and I'll try to answer and edit this post to clarify the confusing bit.

Important extra tip: If you want your leg's piston to extend (telescopically) during its deploy animation, only animate an empty parent object of the piston mesh. The gameObject that you point to with "suspensionTransformName" in the cfg cannot be animated. Place the wheel collider and the actual piston mesh (which you point to with "suspensionTransformName")with its child foot underneath this animated empty object in the hierarchy.

Edited by BahamutoD
Link to comment
Share on other sites

Kipard, does this mean you can continue work on your Skylon? :)

You know, it might :) I'll have to make some changes obviously, but this at least this will allow me to understand some concepts.

I'm still hoping for a gear tutorial with all the bells and whistles, maybe for the firespitter FSwheel module instead of the stock one.

Link to comment
Share on other sites

I believe so, but you'd need multiple ModuleLandingLeg's in the config, so there would be a bunch of duplicate buttons on the same part. If you know any programming, I think it would be easy to write a small plugin to combine the multiple modules into a single button.

However, I've made a part before that had 4 legs built in and it had alot of problems. Something about 4 different colliders on the same part was making it get stuck to the ground, but this was with non-suspension legs, so who knows, maybe it will be fine with wheel colliders.

e: I just remembered the problem also had to do with engines also being in the same part.

Edited by BahamutoD
Link to comment
Share on other sites

I have two problems that I can't seem to solve.

The first is that my legs are always resting at the point where the Wheel Collider hits the ground, even if the legs retract, they still hover above the ground. It seems like for whatever reason that game is using the Wheel Collider as a normal collider. I've made sure that both my pistonCollider and wheelCollider are in the proper place in the heirarchy.

Secondly, my pistons always want to retract to the upper suspension limit if there's any weight on them at all. I can see them move around if I hack gravity, but when I'm on the ground they instantly slide to the upper limit. I've tried changing the spring and damper values to several different things, but that doesn't seem to solve the problem.

Link to comment
Share on other sites

I have two problems that I can't seem to solve.

The first is that my legs are always resting at the point where the Wheel Collider hits the ground, even if the legs retract, they still hover above the ground. It seems like for whatever reason that game is using the Wheel Collider as a normal collider. I've made sure that both my pistonCollider and wheelCollider are in the proper place in the heirarchy.

Secondly, my pistons always want to retract to the upper suspension limit if there's any weight on them at all. I can see them move around if I hack gravity, but when I'm on the ground they instantly slide to the upper limit. I've tried changing the spring and damper values to several different things, but that doesn't seem to solve the problem.

Did you make sure that the colliders are in their proper layers? If so, could you PM me the unity files? I'll try to figure out whats wrong so I can update the tutorial with the info.

Link to comment
Share on other sites

Anyway ... If i'm scanning this topic correctly, these modules aren't designed for attaching parts, say an attach node at the bottom of a landing leg? I wanted to build my own landing gear from combining a rover wheel and landing leg. Yes I can surface attach. And then the stuff floats in the air if I lower or raise a leg.

But I'll take the time to learn Blender, I'll be much happier that way.

Link to comment
Share on other sites

You're gonna have to use Infernal Robotics if you want attached parts to move.

I've figured out how to use IR to run my custom parts. Let me know if you want some help

AdeptUncommonAtlanticblackgoby.gif

edit: whoops BahamutoD, I thought that you were giving advice to the op. I assume you have it all figured out. Azimech I could still give you some pointers though

Edited by clown_baby
Link to comment
Share on other sites

This leg is crude but VERY usefull

http://imgur.com/GXTgIpB,Mh5lSuE,kfz3E69

Without it i woudl probably had to put some standard landing legs on grid segments.

Coudl you possibly keep developing it? Better texture, more detailed model etc.

I agree. I realize BahamutoD merely threw it together as an example, but if he polished it up a bit, it would easily be my favorite landing leg.

Link to comment
Share on other sites

BahumotoD (Or anyone who can answer, really.), if I make a Landing Leg without suspension, would I just have to give the foot a collider? And if I had multiple colliders that moved and intersected on the same part, would that cause anything, like jitteriness?

Link to comment
Share on other sites

So, I was investigating the "multiple legs in one part" thing. It uh, doesn't seem to work.

I did it thusly:

// --- asset parameters ---

MODEL

{

model = NovaPunch2/Parts/NewOdin/OdinShield/shield

scale = 1.0, 1.0, 1.0

rotation = 0, 0, 0

position = 0, 0, 0

}

MODEL

{

model = NovaPunch2/Parts/NewOdin/OdinShield/leg

scale = 1.0, 1.0, 1.0

rotation = 0, 90, 0

position = 0, 0, 0

}

MODEL

{

model = NovaPunch2/Parts/NewOdin/OdinShield/leg

scale = 1.0, 1.0, 1.0

rotation = 0, 0, 0

position = 0, 0, 0

}

MODEL

{

model = NovaPunch2/Parts/NewOdin/OdinShield/leg

scale = 1.0, 1.0, 1.0

rotation = 0, 180, 0

position = 0, 0, 0

}

MODEL

{

model = NovaPunch2/Parts/NewOdin/OdinShield/leg

scale = 1.0, 1.0, 1.0

rotation = 0, 270, 0

position = 0, 0, 0

}

rescaleFactor = 1

(removedirrelevant stuff)

MODULE

{

name = ModuleLandingLeg

animationName = LegDeploy

wheelColliderName = wheelCollider

suspensionTransformName = lowerPiston

orientFootToGround = true

landingFootName = foot

// Axis is aligned forward instead of up

alignFootUp = true

suspensionUpperLimit = 0.2

impactTolerance = 6500

suspensionSpring = 6

suspensionDamper = 1

}

Javascript is disabled. View full album

The leg deploys and functions properly... on one of the four "leg" models I have defined in the config. (in the hierarchy legRoot is a Gameobject at the part origin, so I only needed to rotate the legs in 90deg increments to add all of them to the shield part, which is a wholly uninteresting mesh at this point) - it does indeed collide with the terrain on the launch pad, so that one leg is working right.

The 2nd, 3rd, and 4th legs do not deploy. I also tested it by making the 1st leg be rotated to 90 and the 2nd one with zero rotation, and its still the 1st leg that deploys, so its not rotation related.

It seems that the Landingleg module only recognizes the 1st instance of the leg and/or its animation.

Anyone have any ideas?

It looks like I would either need to animate each leg separately (with a separate animation name and different objectnames) and then have 4 modules in the part config, or I'd have to make the leg and door a separate part to assemble in the VAB (which will make it wobbly)

Link to comment
Share on other sites

When I did multiple legs with the old system, I had all the legs in one model, not separate like that. I don't think my method would work with the new ModuleLandingLeg though. It sucks that what you tried doesn't work =/ I guess the module just takes the first model node :huh:

Link to comment
Share on other sites

BahumotoD (Or anyone who can answer, really.), if I make a Landing Leg without suspension, would I just have to give the foot a collider? And if I had multiple colliders that moved and intersected on the same part, would that cause anything, like jitteriness?

Forgot to reply to this.

If you're not using suspension then I think you might as well just use ModuleAnimateGeneric, or even the old HLandingLeg.

I don't think there's problems with colliders on the same part intersecting, but I'm not 100% 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...