Jump to content

Trailer Hitch Grapple Device


Recommended Posts

I started modding for KSP a few weeks ago for my own edu-tainment, and I have an idea for a part I want to make but not sure where or how to start.

I want to make a trailer hitch part (akin to semi-truck/trailer hitches) that can give free movement once it joins two parts (akin to the stock klaw). I imported the klaw into Blender but I'm so overwhelmed by the sheer number of objects in the klaw model that it's difficult to decipher what objects do what. The klaw's config has FXModuleLookAtConstraint with almost as many references. I'm only looking to move one object with my part idea to keep things simple for the moment while still emulating the klaw's free joint movement.

So how can I set this up to do what I want to do? Is it manageable for a newbie, or am I in over my head?

Link to comment
Share on other sites

Hi, the fx constraint modules function by simulating animation of a part, for instance, you want to have a ram opening a claw, well the look  at and constraints when setup correctly allow the ram to function without actually having to create a physical animation all you animate is the opening claw.  For your purposes you only need the part that is the Base and trigger  , ignore all the constraint stuff ( btw for future ref the constraint look at axis is Z+. in that two objects must have the z+ axis rotated to face each other in order for it to work)

This can be modeled in two simple parts an outer and an inner, the inner part is the actual attachment part and is the part that will move when you click arm

  For a good easy to follow example of how it works when not a claw, check out the SM Marine mod, in the tugboat kit there are two parts, one a pushbar, and the other a truck tyre style fender, both are module wise and as far as the game knows claws,  these parts allow the tugs to attach and drag things much bigger things around .

Do note that I've tried this method with vertical  fifth wheel lookalikes on my up coming SM AFV mod but it's no good that way around as you can't get enough force to trigger the grab , without batting the trailer across the airfield.  The best way is to mount it horizontally  on the rear of the tow vehicle

Spoiler

aorbm1D.png

 

Edited by SpannerMonkey(smce)
Link to comment
Share on other sites

So I took Spanner's comment above and ran with it, building and testing and tweaking for the past couple days (real life interrupted me too), and finally arriving at a working solution. But now I have a new small question: how can I increase the pivot range of a klaw-type device? I tried adding a line listed as Public Attributes from this page in my part config but it didn't seem to work. I'm guessing pivotRange only works under to hood and is not changeable, but I'm hoping I'm wrong. Can it be changed?

Link to comment
Share on other sites

I tried 90, 180 and 360 for pivotRange, didn't occur to me to try using +/-1.0 as rotation value because the sample value for pivotRange on the page had 30 in it (actual value is "30f", if F means something appropriate here). Should I use 1.0 for the value?

Link to comment
Share on other sites

F is for float and floats are usually expressed as 1.0,  0.1 rather than integers 1,2,3  etc   but  I'm sure it'd read 1 as 1 , just wont be able to read 180, 90 etc  and would like show an error in the log for an  incorrect format.  Golden rule 390276.3  "when tinkering , check the logs first", a lot of the time if you search for the part name you'll find the answers in that same log    

I doubt they'd have left it 180 or above as that would usually mean the object being grappled would clip into the grappling object, and either be very bad, or look awful. But  30deg  yeah I can see that working most of the time,  so perhaps 30.0 or is that now a double?? i dunno it's code stuff :)

 

Link to comment
Share on other sites

The config system doesn't care whether you put 1 or 1.0 as it'll know what type it's expecting and convert it properly.  It'll likely choke on 1f or 1.0f though... I've never seen a config value use it.  That's only for writing the value in C# code.  (For the record, in C#, 1 is an int which will convert to a float, but 1.0 is a double which will not.  1f and 1.0f are both floats and are equivalent.)

And yeah unfortunately just because pivotRange is in the API docs doesn't mean it's loadable via part config.  It may have been omitted (whether accidentally or deliberately is anyone's guess).  Though to be sure I would try a value like 29, or something else that'll be apparent when you load your part but is still fairly close to 30, just in case the value is clamped to a more narrow range.  Failing that, it would need to be set via code... hmm unless maybe ModuleManager could do it, but I haven't got into MM yet so I don't know whether it operates at the config level or the code level... nope, I got curious and looked, it's config level.  Oh well.

Hey maybe there should be a dedicated "Ask a Coder" thread for part-maker questions like this... dunno where to put it though (here or the Plug-In forum?).  My main thing is coding but luckily I sometimes dabble in model making so I like like to poke in here from time to time in case I can learn stuff.  :D

Edited by paulprogart
MM correction, also C# int/float clarification
Link to comment
Share on other sites

I had a nagging suspicion my solution would be in coding. As I've only started modding, I haven't gotten into learning anything related to code outside of MM patches. I would like to learn code but not quite yet. When I do start coding, I'm sure I can find great help in the Plugin Forum.

As for my hitch idea, I'll experiment so more, see how the stock klaw, Spanner's parts and my hitch compare and see what I can do. Thank you guys for your help so far. :)

Link to comment
Share on other sites

So I've done some digging and testing I've figured something out: pivotRange is a configurable stat, and it only accepts values with decimals (e.g. 20.0) which I thought I tested but apparently not. Also, any value is accepted and is used as degrees (expected), though any value above 180 gives nearly unlimited swing. So it will be useful for my purpose, as I had hoped.

So, thanks again for your help @paulprogart and @SpannerMonkey(smce) for your help on this matter. As for me, my pivotRange = 359.9 because I can. :) 

Link to comment
Share on other sites

That's weird because I have used config values without decimals in my own add-ons and it takes them fine, but this is for config settings rather than parts, so perhaps the part .cfg loader is stricter.  (ConfigNode is a behemoth of a class, who knows how consistent it is.)

Anyhow, glad you got it, sounds like a neat little mod.  (BTW I love the thread title... it's like one of those cheeky long names the Mythbusters would use when they weren't allowed to say brand names.)

Link to comment
Share on other sites

  • 2 weeks later...

So after a bit more playing around with what little free time I had this week, I still seem to be having the same issue. I read the wiki on the Advanced Grabbing Unit (when it worked, seems to be empty at this time) that the pivot on the grabber can bend at the specified pivotRange (what I was testing with an MK1 Command Pod) but the pivot cannot twist (what I've been trying to do with this trailer)*. I even moved the attach point on the model in Unity to see if that made a difference (doesn't appear to). This frustrates and saddens me. The good part is that the models for the male and female hitch parts hook well enough together, due to my custom colliders, that they will hold together under "normal" driving conditions, though I haven't tested them further than that. For now, I'll just tidy up the models. In the meantime, any other ideas on how I can get the connection to work like real hitches? Maybe a plugin like Kerbal Attachment System?

EDIT: *relevant wiki bit about Klaw pivot*

Quote

Once the AGU is attached, its claw's pivot can be toggled. The pivot is locked whenever armed and not attached, but can then be unlocked by right-clicking the AGU and choosing Free Pivot. While freed, reaction wheels or RCS can be used to alter the craft's pitch and yaw (from the AGU's perspective) relative to the target, but not roll; the claw turns, not twists.

EDIT2: I tinkered with the grappleNode orientation in Unity, but the game doesn't care about that orientation except in part alignment before it attaches. It never occurred to me until this morning to rotate the whole model to make it work. ModuleGrappleNode apparently uses the +Y axis to determine how the pivot behaves once something attaches. Rotating the model in Unity to have it's +Y to point toward the global -Z will make the hitch behave as I intend. And like Spanner mentioned above, the trailer does clip into the truck and looks weird, though there seems to be no ill effects beyond that.

EDIT3: Not sure if my description reflects what's in my head, maybe pics in this Imgur album will help.

Edited by SchwinnTropius
wiki suddenly works after posting, quoted relevant bits; Unity and editors rotation info
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...