Jump to content

Override Player Thrust Input


Recommended Posts

The title basically says it all: I want full control over the engine throttle, without the player being able to influence it. I have searched throught the Plugin Dev Help forum, but found nothing, although this has been done already by modders. Is this problem so trivial? :D

Currently I'm doing this:

engine.currentThrottle = newThrottle;

engine.finalThrust = engine.CalculateThrust();

which seems to do the job, but the engine overrides this with the player input. I currently have all the fuel consumption with none of the physics, and the throttle fluctuates.

I have set engine.manuallyOverridden = true, but that seems to do nothing in this respect.

I think that there are 3 solutions to this:

1. Prevent the engine from reading the player throttle input

2. replace the player input, so that the engine reads my input as player input

3. Override the throttle-values, after the engine has pulled the player input, but before the physics get calculated

I guess I don't have the right permission to do 1, and 3 may all happen in one method, so I maybe can't "inject" the change between the player input read and the physics calculation.

So 2 is the way to go, I think.

I'd be glad, if anyone could help.

greetings

Simon

Link to comment
Share on other sites

If you want to set it globally for all engines on the craft, that's very simple. In your fixed update loop, you can set the throttle percentage using:

FlightInputHandler.state.mainThrottle = [COLOR=#ff0000]<0-1> float for throttle percentage on the active vessel. Will retain the value if your code is not constantly updating[/COLOR]

More complex vessel control (other vessels and really any further control input) are typically handled through callbacks like these (there are 4 in total, the linked two plus OnAutoPilotUpdate and OnFlyByWire. They are always called in the same order and which to use depends on what you need). The function you give the callback is passed the current control state and you can then modify it before it goes to the next stage (replacing the FixedUpdate loop in some cases) (Example usage). You can get the same effect most of the time by directly assigning to the vessel.ctrlState if you just want to keep things simple.

Assuming you don't want to adjust the thrust limiter, the least hacky way of modifying throttle on a per engine basis would involve creating an engine subclass where you update either the output thrust or the maximum thrust with your custom calculation. Doing it outside the engine module just sounds like a PITA

Edited by Crzyrndm
Link to comment
Share on other sites

I actually want to modify the thrust on a per engine basis, and thought about using the thrustlimiter, but I couldn't find it anywhere. It would be a pretty easy solution for my problem though, and I will handle the total thrust of the vessel elsewhere, so I don't see any problem. But where can I modify it? I didn't find it in the ModuleEngines.

I will also look into your other solutions, but thrustlimiter seems to be the simplest and most promising right now.

very helpfull post, thank you!

Link to comment
Share on other sites

What exactly do you mean by that? I could create a PartModule and append it to the part with the engine.

Or would you rather derive a class from the ModuleEngines, and replace the old ModuleEngines?

btw, I want to use this to create a mod that allows for asymetric spacecrafts, or ones that have shifting CoMs by adjusting the thrust of each engine (so that you don't have to balance them for hours) That would allow for some awesome cargo VTOL. I think I have the theory down, but I'm struggling with the implimentation. Am I missing something obvious, which has all the other modders prevented from doing this?

Link to comment
Share on other sites

You'll want a subclass of ModuleEnginesFX, not ModuleEngines. The majority of engines don't use the older class anymore.

To have a part use your custom class, you'll want to use a module manager patch to change the name field of the engine module in all applicable parts (something close to the following should work)

// any part with a ModuleEngine or ModuleEnginesFX module (using the wildcard to catch both)
@PART
[*]:HAS[@MODULE[ModuleEngines*]]
{
// Every module named ModuleEngines*
@MODULE[ModuleEngines*],*
{
name = MyNewSubclass
}
}

I know there's a few mods in this vein around. Davon Throttle Control and Throttle Controlled Avionics are the two that come to mind but there's probably others

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