Jump to content

The official unoffical "help a fellow plugin developer" thread


Recommended Posts

Hi! I am working on creating come configs to extend KAS grab and store functionality to some mods that do not have it, but I am having a bit of an issue with one of the variables.

According to the KAS Wiki, the evaPartDir setting determines which way the part is pointed when strapped on the Kerbal's back. I cannot seem to get my head around these settings, and adjusting the numbers and reloading the configs is crushing my soul.

Here is the cfg I am fretting over.


//////// TAC Life Support ////////
// --- Small Hex Cans ---
@PART[HexCan*Small]
{
MODULE
{
name = KASModuleGrab
evaPartPos = (0.0, 0.0, -0.17)
evaPartDir = (0,0,-1) //<---- THIS IS MAKING ME CRAZY!
addPartMass = true
storable = true
storedSize = 18
attachOnPart = true
attachOnEva = false
attachOnStatic = false
attachSendMsgOnly = false
}
}

This puts the small hex-can on the Kerbonaut going straight up and down. It seems more like a sane Kerbal would have it go across his back, especially for walking with it. However, I cannot seem to get it to rotate 90 degrees. I have tried all sorts of number combinations but I seem to be getting nowhere. Anyone have a suggestion?

JNbcsHK.jpg

Link to comment
Share on other sites

This puts the small hex-can on the Kerbonaut going straight up and down. It seems more like a sane Kerbal would have it go across his back, especially for walking with it. However, I cannot seem to get it to rotate 90 degrees. I have tried all sorts of number combinations but I seem to be getting nowhere. Anyone have a suggestion?

It is impossible. What you can do is fiddle with the offsets and direction so it doesn't clip into ground or the helmet. Here are my configs: https://gist.github.com/angavrilov/8971612#file-modulemanager_tac-cfg

Note that those configs are for a new KAS version with a bunch of fixes that is to be released eventually, and it changes some internal math in how those coordinates are interpreted; so with the current version the coordinates may be off (or maybe not).

Edited by a.g.
Link to comment
Share on other sites

It is impossible. What you can do is fiddle with the offsets and direction so it doesn't clip into ground or the helmet. Here are my configs: https://gist.github.com/angavrilov/8971612#file-modulemanager_tac-cfg

Note that those configs are for a new KAS version with a bunch of fixes that is to be released eventually, and it changes some internal math in how those coordinates are interpreted; so with the current version the coordinates may be off (or maybe not).

Ah, well I am glad to know I am not losing it. Thanks for sharing your configs. I think a lot of people are looking for an easy way to add KAS compatibility to mods that don't have it, like B9 and TAC stuff. I see you used helmetCollider as one of the evaTransformName settings. That is a neat idea, I'll have to try that on parts where it makes sense.

Link to comment
Share on other sites

I've just noticed in the source code that there is an undocumented in-game GUI, which allows tweaking those offset and direction numbers directly in the flight scene. To activate, press Ctrl-K to open the window, then Ctrl-click on your test part to select it. After that you can use buttons in the window to tweak the values in varying increments, and then press G-G to drop and re-grab the part and view the new position. This makes finding the exactly right coordinates a lot easier.

Link to comment
Share on other sites

Is there a way to control what orbit is drawn in Map Mode? Some way that I could provide a set of times/coordinates and draw based on that, instead of the ellipses worked out by the orbital parameters? It seems like I want to override the DrawOrbit() method. What about for following such an orbit on rails? How do I modify that?

Would Interstellar Quest be a place to look, specifically the warp drive? Or does it do something different (I haven't used it)? Maybe I'll try taking a look there...

Link to comment
Share on other sites

So I posted a thread about this, but got no answer.

How do you get a Part's transform in world space? All the obvious routes seem to given an unmoving point on the launchpad.

Sometimes nobody answers because it's apparent you didn't bother to try anything or look anything up.

Google: Unity transform, get result

Variables

childCount The number of children the Transform has.

eulerAngles The rotation as Euler angles in degrees.

forward The blue axis of the transform in world space.

hasChanged Has the transform changed since the last time the flag was set to 'false'?

localEulerAngles The rotation as Euler angles in degrees relative to the parent transform's rotation.

localPosition Position of the transform relative to the parent transform.

localRotation The rotation of the transform relative to the parent transform's rotation.

localScale The scale of the transform relative to the parent.

localToWorldMatrix Matrix that transforms a point from local space into world space (Read Only).

lossyScale The global scale of the object (Read Only).

parent The parent of the transform.

position The position of the transform in world space.

right The red axis of the transform in world space.

root Returns the topmost transform in the hierarchy.

rotation The rotation of the transform in world space stored as a Quaternion.

up The green axis of the transform in world space.

worldToLocalMatrix Matrix that transforms a point from world space into local space (Read Only).

Part.transform.position is your answer

Link to comment
Share on other sites

I tried that, and it didn't work. That's why I'm asking for help.

Both Part.transform.position and part.partTransform.position give the root of a vessel on the launchpad, and then don't move. The rotation of the transform works fine, but the position doesn't.

That or I'm using the graphical debugging wrong, but I worked that straight from the examples on the wiki.

I'm asking because maybe there is some quirk that I don't know about, and people with experience in the subject can easily identify. That is, of course, the point of having a help forum in first place. It's not so that lazy ignorant people can easy questions, it's so modders who don't know all the little things about the KSP modding environment can draw on the experience of those who have worked with it for longer.

But thanks for being condescending.

Link to comment
Share on other sites

I'm asking because maybe there is some quirk that I don't know about, and people with experience in the subject can easily identify. That is, of course, the point of having a help forum in first place. It's not so that lazy ignorant people can easy questions, it's so modders who don't know all the little things about the KSP modding environment can draw on the experience of those who have worked with it for longer.

But thanks for being condescending.

I wasn't trying to be condescending. I was trying to tell you why you didn't receive an answer instead of cold shouldering you like everybody else did. Read your post again from my perspective.

Part.transform.position and part.partTransform.position give the root of a vessel on the launchpad

Only the rootPart's transform does. You're going to need to show some code to get any help. Whatever it is appears to be wrong and leads you to wrong conclusions

Link to comment
Share on other sites

Right, sorry. I get snide when I'm tired. Thanks for helping.

The code in question is in a PartModule which I've given to every manned pod. It's called every update from each of the three command parts on the vessel, which I can tell from print statements.

The rotation of the debugging line works, but the position just stays on the pad. I'm probably overlooking something, but I've been poring over this code for so long that I need fresh eyes.



protected Rect windowPos = new Rect(40,40,1,1);

// debugging
private GameObject obj;
private LineRenderer line;

private void updateWindowSize()
{

[INDENT]//print("CTS_Node updating window size in part " + part.partName);

// visual debugging
Destroy(obj);
obj = new GameObject("Line");
obj.transform.position = part.transform.position; //THIS DOESN'T WORK

line = obj.AddComponent<LineRenderer>();
line.material = new Material(Shader.Find("Particles/Additive"));
line.SetColors(Color.red, Color.yellow);
line.SetWidth(0.1f, 0.1f);
line.SetVertexCount(2);
line.SetPosition(0, Vector3.zero);
line.SetPosition(1, part.transform.forward * 2); //THIS WORKS

// transform part position to screen space
Vector3 screenPos = Camera.current.WorldToScreenPoint(part.transform.position);

windowPos = new Rect(screenPos.x, screenPos.z, 40, part.protoModuleCrew.Count * 32 + 8 + 64);[/INDENT]


}

Link to comment
Share on other sites

I've just noticed in the source code that there is an undocumented in-game GUI, which allows tweaking those offset and direction numbers directly in the flight scene. To activate, press Ctrl-K to open the window, then Ctrl-click on your test part to select it. After that you can use buttons in the window to tweak the values in varying increments, and then press G-G to drop and re-grab the part and view the new position. This makes finding the exactly right coordinates a lot easier.

That. Is. Awesome! I just used it to tweak the settings on a bunch of parts and it makes it so much easier. Still wasn't able to turn it the way I wanted, but we'll see what the next release of KAS brings. THANK YOU, a.g.!!!!

Link to comment
Share on other sites

The rotation of the debugging line works, but the position just stays on the pad. I'm probably overlooking something, but I've been poring over this code for so long that I need fresh eyes.

When you create LineRenderer, its useWorldSpace property defaults to true. Guess what the Unity docs say about it?

Use World Space If enabled, the object's position is ignored, and the lines are rendered around world origin.

So that's why it's not going anywhere. line.useWorldSpace = false should fix it.

As an aside, why create a new GO and destroy the old one every loop? If you create your debug line in the Start() function of your PartModule and attach its transform to your parent (obj.transform.parent = part.transform), you won't need to update its position every frame. It'll be handled for you.

Link to comment
Share on other sites

Thank you for helping me with my question a while ago, NathanKell. I didn't properly thank you.

Now for another :sticktongue: For the mod I'm working on, I am implementing first person EVA. I want to change the controls of kerbals on EVA. Specifically, I want to make the kerbal follow the rotation of the mouse X axes while standing still, and make the kerbal follow both the X and Y axes while in space. Basically, implement FPS controls. Being really new to C# and Unity and scripting in general, it would be extremely helpful if someone could point me in the right direction. I don't want anything written for me, I just need an idea of where to start at. I've had no luck with the way I've been going about it.

I was thinking to completely override the stock controls, replacing them with a standard FPS controller script by removing whatever component is attached to an EVA kerbal that defines movement, and adding the MouseLook component and FPSController Component. I think the PartModule KerbalEVA is where I need to start but again, I've had no luck with that so far. Is there a simpler way I could be going about this?

Thanks in advance to anyone who takes the time to reply!

Link to comment
Share on other sites

Hi, people. I'm trying to develop an update to by existing mod and I'm having a little trouble with the plugin. I'm trying to code the part the plugin is linked to so that it changes the result when the ship is on the launchpad, the runway, etc. I've tried looking at the "landedAt" string, but I've had no luck.:huh: Anyone got any ideas? :)

Link to comment
Share on other sites

Hi, people. I'm trying to develop an update to by existing mod and I'm having a little trouble with the plugin. I'm trying to code the part the plugin is linked to so that it changes the result when the ship is on the launchpad, the runway, etc. I've tried looking at the "landedAt" string, but I've had no luck.:huh: Anyone got any ideas? :)

Look into biomes and vessel.situation (for flying over, landed at, in space above, etc)

Link to comment
Share on other sites

Look into biomes and vessel.situation (for flying over, landed at, in space above, etc)

I looked at "this.vessel.situation == Vessel.Situations." but it looks like the only options are "LANDED, PRELAUNCH, SPLASHED" etc. Bearing in mind what you'd said, I looked into different biomes. I tried a new code, but I still couldn't get it to work. As a little explanation, the resource intake is supposed to be different depending on where on Kerbin the vessel is landed. Here are a couple of different examples. (Also, before I tried to specify different biomes, the "ExtractorActive" bool wasn't turning false when the given limit was reached, as it was supposed to. Hope that makes sense :P)

Example 1:

switch (this.vessel.landedAt)
{
case "Launch Pad" :
if (this.part.RequestResource("LifeSpecimens", 0 * TimeWarp.deltaTime) != 1)
{
ExtractorActive = false;
ExtractorStatus = "Process Completed";
this.part.RequestResource("ElectricCharge", 0.025 * TimeWarp.deltaTime);
}
else
{
ExtractorActive = true;
}

break;

Example 2:

case "Grasslands" :
if (this.part.RequestResource("LifeSpecimens", -5 * TimeWarp.deltaTime) > 39.99)
{
ExtractorActive = false;
ExtractorStatus = "Process Completed";
this.part.RequestResource("ElectricCharge", 0.025 * TimeWarp.deltaTime);
}
else
{
ExtractorActive = true;
}
break;

Link to comment
Share on other sites

I looked at "this.vessel.situation == Vessel.Situations." but it looks like the only options are "LANDED, PRELAUNCH, SPLASHED" etc. Bearing in mind what you'd said, I looked into different biomes. I tried a new code, but I still couldn't get it to work. As a little explanation, the resource intake is supposed to be different depending on where on Kerbin the vessel is landed.

If you're looking for the SrfLanded, InSpaceLow, etc... you should try poking around with ExperimentSituations, I'm not sure exactly how it works as I've only been using it to return one specific result.

As for biomes, check back a few pages. For KSC, LaunchPad, and Runway, you'll need to find another way (I use vessel.landedAt, but that only works on the surface) because the biome check will only return "shores" for anywhere around the KSC.

Link to comment
Share on other sites

I'm looking for a way to tell if any vessels are going to change SOI while in the SpaceCenter and other non-flight scenes as I'm going to be jumping the game time by several hours or days and want to disallow that when there will be an SOI change during that time. The options available in the vessel.orbit are somewhat confusing and the ones I've tested don't give me a time or even a "yes, there will be an SOI change eventually", so if anyone knows of a way of performing this check it would help me out a bunch. Thanks in advance :)

Edit: I took a look at Kerbal Alarm Clock and figured out how they check for SOI transitions, but thanks anyway!

Edit 2: Apparently in the space center scene they don't keep track of vessel.orbit.patchEndTransition, so while transitions will still occur they aren't exactly predictable. Anyone have any ideas that could help? Also, you can't timewarp either, but can change the Universal Time. I could write my own timewarp code that changes the UT, but that may cause issues.

Edited by magico13
Link to comment
Share on other sites

Still can't figure this out; any help please?

Define "target node". You want to place a maneuver node on a particular position on the planet? I have yet to find a way to position maneuver nodes off of a given orbit path. Temporarily modifying an orbit works but it's hacky and not all the time.

If you want to position a maneuver node such that executing it would result in the vessel's orbit intersecting a position on a body, you might want to look at the source to MechJeb.

Link to comment
Share on other sites

I'm kinda thinking along the lines of when you right-click on a vessel and select as target. Instead I'd just like to "target" a given surface coordinate.

I'm certainly not the best person to ask about stuff like this, but couldn't you spawn a vessel with just a silly root part (like a metal plate) at the area in question and then set it as the target? Then remove it when they get within physics range or something like that.

Link to comment
Share on other sites

Hi, people. I'm aware that with KSP updates, plugins can break and it seems that somewhere in the update process, a code that my plugin used in previous versions doesn't work any more. An example of the basic idea of the code is this:


if(partActive == true)
{
if(this.part.RequestResource("Resource", -2 * TimeWarp.deltaTime) > 19.99)
{
partActive = false;
}
else
{
partActive = true;
}
}

The idea here is that when the amount of "Resource" reaches 20, the part will deactivate (and stop gathering the resource). However, this doesn't seem to work anymore in 0.23. It just gathers the resource until you manually deactivate the unit, which is no good if it is essential that it cannot gather any more of "Resource" when it hits 20. Any ideas, anyone? Thanks. :)

Link to comment
Share on other sites

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