Jump to content

[Plugin] 747-Style Landing Gear (Advanced Animatronic Landing Gear plugin)


OrbitusII

Recommended Posts

so is this going to be a unity component as well?

What I'm thinking of doing is making the plugin for KSP and then releasing some tools for setting up the gear in Unity. This all depends on whether or not I can make it easy to configure of course, and my attempts with landing gear besides the 747's have not gone well, unfortunately. For some reason the gear I've been trying to set up are not cooperating with anything I do to them, so there will probably be a rewrite of the code soon.

Link to comment
Share on other sites

In Unity, the spring constant for a wheel collider is stored in the "SuspensionSpring" variable, so it can be changed to be higher or lower depending on the needs of that collider......

hello, so it's possible to add a little module to tweak this parameter by [KSPFIELD] ?

(give to me the opportunity to start study plugins)

I demand that because unlike the stock gear small gear bay my gear is tweaked only for 20 t approximately , to have

a functional suspension in this range of masse.

In the same way do you think the Suspension Distance is accessible in game by [KSPFIELD] ? it will be useful if is possible

to achieve one of my future plan if I have time :wink:.

The plugin look promising bravo !!

steph

Edited by stephm
Link to comment
Share on other sites

hello, so it's possible to add a little module to tweak this parameter by [KSPFIELD] ?

(give to me the opportunity to start study plugins)

I demand that because unlike the stock gear small gear bay my gear is tweaked only for 20 t approximately , to have

a functional suspension in this range of masse.

In the same way do you think the Suspension Distance is accessible in game by [KSPFIELD] ? it will be useful if is possible

to achieve one of my future plan if I have time :wink:.

The plugin look promising bravo !!

steph

Indirectly, this is indeed possible! While SuspensionSpring on a wheel collider cannot be directly accessed by a [KSPField], you can store the number in a [KSPField] variable and then set it whenever the part loads.

Link to comment
Share on other sites

hi !

thank you very much !

Now,I thinking about lot of thing to do :D, but for me it's a long and difficult way...(need to learn plenty of things héhé)

but it's great !

sometime just a little confirmation can provide a useful help :wink:.. KSP is a very cool platform for modding !!

steph

@+

Link to comment
Share on other sites

sometime just a little confirmation can provide a useful help :wink:.. KSP is a very cool platform for modding !!

I agree, and when you do things right the results are awesome. :D

Ended up rewriting the code for the landing gear and the results are much better. I don't have positioning issues any more and setup is a lot more intuitive! I'll keep working with this iteration of code.

Update: Really glad I rewrote the code! I'm now able to set up Capt. Kipard's prototype gear with no trouble whatsoever! It's a little confusing to animate but that's a small price to pay for the massively improved functionality! I'll try to post a progress update sometime today.

Edited by OrbitusII
Link to comment
Share on other sites

Update video!

Got Capt. Kipard's Skylon landing gear configured! The gear here are dropped from about 10 meters up with a low spring setting to show the full compression.

The animation on the torque links needs a little refining, which is why I included footage showing the gear working without animations (the old code could not do that) as confirmation that you can still use FXLookAT or whatever.

Link to comment
Share on other sites

very nice! so animation as in a Unity animation clip or imported animation? the Wheel collider compression drives the animation ?

It can use Unity animations or animations bundled with the model itself, all the code needs is for the animation to be attached to the animated object.

That is correct, the compression of the wheel collider's suspension does indeed drive the animation. It uses an indirect method to do so, but that is effectively how it works.

The script casts a ray down from the wheel collider to the ground, returning the data it gets if/when it hits something. It then takes the distance from the point the ray hits to the maximum extension of the wheel collider and turns that into a percentage value based on the "compression" variable in the script. This percentage value is then used to set the time of the animation. For example, when the suspension is completely compressed, the animation will go to time 0. When the gear are off of the ground and completely uncompressed, the animation goes to time 1. Based off of the compression experienced by the suspension on the wheel collider, the animation can therefore be anywhere within times 0 and 1.

In addition to using the data it gets from the raycast to set the time of the animation, the script uses the point hit to set the position of the GroundContact object's Transform component. This is similar to how the stock wheels do it, except that the stock wheels position their wheels at the hit point plus some extra height based off of the radius of the wheel. AALG places the GroundContact object directly at the hit point, simplifying code a little bit. The original code for the AALG would use the same method as stock wheels, which worked for simpler models like the 747 landing gear but quickly fell apart as soon as something like Capt Kipard's landing gear came along. The current code is slightly harder to set up in Unity in terms of positioning things (like you need to know the radius of the wheel meshes), but it's actually a lot better in terms of accuracy.


wheelBase.position = hit.point+(wheel.radius+heightOffset)*wheel.transform.up+(perc*traverse)*wheel.transform.up;
//Complicated, ugly, and not always accurate, especially with things other than the simple 747 gear I designed for testing this.
//Doesn't always position things right, even if they're set up 100% correctly :(

NEW:
groundContact.position = hit.point;
//Very simple and elegant. Works like a charm for anything, even if it's not set up 100% correctly
OLD:

Needless to say, the original code was very convoluted and will not be used in the final plugin. The new stuff is awesomely simple. Just look at the hierarchy needed to get it to work!

BeYNx6x.png

It can work satisfactorily with only the main parent, WheelCollider, and GroundContact objects! Now that's simple setup!

Link to comment
Share on other sites

Update: Started working on reimplementing the deploy/retract system for the landing gear and it's already going a lot better than before! There's just a little bit of work to do before the gear can be deployed or retracted from any point in their animation like stock wheels. What I think I'll do for this is make it a toggle in the config file so that mod creators can decide if they want their landing gear to be able to stop deploying/retracting at any time.

Edit: Getting the landing gear to stop and reverse their deploy/retract is giving me some minor issues with the mode switch, so I'm gonna leave it alone for now and revisit it later on.

Edited by OrbitusII
Link to comment
Share on other sites

Absolutely first class work!

For the retract animation conumdrum, see BahamutoD's critter crawler. He tackles this in a very clever way (in case you haven't already).

Edit: I might have misunderstood what you're trying to do, but it's worth a peek either way.

Looking forward to seeing this.

Edited by lo-fi
Link to comment
Share on other sites

Absolutely first class work!

For the retract animation conumdrum, see BahamutoD's critter crawler. He tackles this in a very clever way (in case you haven't already).

Edit: I might have misunderstood what you're trying to do, but it's worth a peek either way.

Looking forward to seeing this.

I'll take a look at that, thanks! Even if it's not entirely relevant I might learn something. The issue with toggling the deploy/retract mid-animation is the timing of the mode switch, it works fine otherwise.

In any case, I got the landing gear animation system done and working!

Javascript is disabled. View full album

Capt Kipard's landing gear are effectively complete in terms of Unity setup (although there's a couple things I'd like to fix).

The torque links on the wheel suspension are animated based on the compression of the wheel, the doors and main gear leg are animated for deployment, and the piston on the back (the two gray things) are aligned with a simple alignment script that should function similarly to FXLookAt (or whatever it's called). I could certainly animate them with the rest of the landing gear deployment, however!

Just two more things to work on before I start turning the Unity-based code into a KSP-compatible dll: steering and brakes! These will be easy in Unity compared to the rest of the stuff but I expect it will be a little tricky in KSP since the per-vessel input is harder to find than basing those values off of raw input.

Link to comment
Share on other sites

Take a look at my AlphaModuleTrack class. Its commented, you'll find the this.vessel.CtrlState.foo stuff quite easy to hook into and the brakes action group is in there too. Very, very easy compared to what you've just tackled. Anything I can help with, just shout.

Skylon gear looks superb!

Edit: this.vessel.ctrlstate.wheelsteer is what you're looking for (from memory, probably missing some caps). I'd maybe look at implementing a speed based steeringcurve lookup too, which again you can find in the alpha tracks for quick reference.

Edited by lo-fi
Link to comment
Share on other sites

Take a look at my AlphaModuleTrack class. Its commented, you'll find the this.vessel.CtrlState.foo stuff quite easy to hook into and the brakes action group is in there too. Very, very easy compared to what you've just tackled. Anything I can help with, just shout.

Skylon gear looks superb!

Good to know, thanks! I just downloaded it so that I can check it out. I've had Firespitter's FSwheel source code bookmarked for a little while now as well, so there's lots of reference material here. :D

Link to comment
Share on other sites

Ok, got steering done in Unity, so I'm just about ready to start turning it into a plugin! Unfortunately I'm going to wait until tomorrow to start because I have things I need to do today (notably homework).

Since a couple people expressed interest in seeing how it works I'm going to put a Unity Package in the OP, containing the source code and a demo scene featuring the Skylon forward landing gear made by Capt. Kipard. He made that model available in this post: Main Landing Gear Rigging/Animating Thread

Link to comment
Share on other sites

So I might need to increase the power in the springs on those landing gear...

7J2TCho.png

Edit: HOLY CRAP. KSP's wheel collider handling is convoluted as heck!

9aCvkYT.png

No, it should not be floating like that. It is also floating backwards down the runway at 0.1m/s. It doesn't stop, it can't be stopped. If you mess with it too much, the wheelcollider clips through the ground.

It seems to want to be set up in Unity like the stock wheels, which is just wrong! It shouldn't have to since there is no dependency on the stock modules (because they are trash). If I have to set up the gear like a stock wheel, which is what this plugin is trying to avoid, then I'm going to contact Squad about throwing out their entire wheel code and rewriting it from scratch (in fact, I probably will anyway).

One thing that is working is the visual alignment. It works fine, animating the compression like a pro... when the landing gear suspension actually compresses! I'm guessing that there is some code somewhere in KSP that forces wheelcolliders to have a specific spring value, regardless of what it's set to in Unity. I'm testing it to see if the suspension compresses more with more weight (as it should) but considering what's gone on so far it wouldn't surprise me in the least.

Edit 2: Thank goodness. There is no suspension enforcement code, I just have the suspension set moderately high, but the floating and drifting issue remains.

Edited by OrbitusII
Link to comment
Share on other sites

Hello, and great work! Just wondering, will the idea of this be able to be put on any type of wheel? (Sorry if you have answered this already, I'm not the brightest at times!) I would like to use this with my (very very WIP) mod, basically a modern variant of the Firespitter parts pack. Link;http://forum.kerbalspaceprogram.com/threads/84903-Modded-Fighter-Jets-(EF2000) thanks!

Link to comment
Share on other sites

Hello, and great work! Just wondering, will the idea of this be able to be put on any type of wheel? (Sorry if you have answered this already, I'm not the brightest at times!) I would like to use this with my (very very WIP) mod, basically a modern variant of the Firespitter parts pack. Link;http://forum.kerbalspaceprogram.com/threads/84903-Modded-Fighter-Jets-(EF2000) thanks!

Depending on what I figure out with the Unity setup, it may or may not be able to handle parts made with Firespitter or stock modules.

If I can get it to work with its own hierarchy, parts will need to be reconfigured in Unity to work correctly. If I can't and have to fall back to the horrendous stock hierarchy then it should work just fine with parts made for Firespitter. Unfortunately, if a part is not configured to have gear compression animations then it will not be able to animate it no matter what.

(un)Fortunately, I may have to change parts of the code to account for KSP's wheel hierarchy requirements, so switching landing gear part modules to this one may be a possibility.

Edit: I think I may have a workaround for the floating, which is just the wheel collider not moving with the animation like it should (KSP's fault, yet again) but I'm sick of dealing with it for today.

Edited by OrbitusII
Link to comment
Share on other sites

Well, you'll have one download waiting here for that four-wheel bogie setup if it can be scaled down to be used with stock parts. I've always wanted a bogie for my rough-field planes.

Awesome stuff, be sure to post pics!

I'll take a look at what you posted, see what I can find out for you. Been down this road myself, just not with gear. Lets get this nailed!

I appreciate it, would you like me to send you the current code for the plugin so you can take a look at it?

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