Jump to content

How to detect if there's *player* control input to a vessel?


Recommended Posts

Let's say I want to test "is this vessel currently receiving any control input".

The only place I know how to look is FlightGlobals.ActiveVessel.ctrlState.

This gets me an instance of FlightCtrlState, where I can, for example, check for pitch, yaw, and roll (and the trim equivalents thereof).

That's great, and it almost gets me what I want... except that it tells whether the ship is receiving any control input, including not only the player but also SAS.  In other words, if SAS is active, my test will always say that it's receiving control input, even if it's just floating there in space.

How can I check to see "is there any pitch, yaw, or control input other than from SAS"?  i.e. "is the player hands-off the controls or not"?

Link to comment
Share on other sites

Little disclaimer: I'm far away from beein good in this and I have no clue how to code it properly in this case :P

How about getting the config node of the keybindings, get the keys for pitch, roll,yaw and than check if these keys are pressed (Input.GetKeyDown(Keycode))? :)

Edited by 4x4cheesecake
Link to comment
Share on other sites

23 minutes ago, 4x4cheesecake said:

How about getting the config node of the keybindings, get the keys for pitch, roll,yaw and than check if these keys are pressed (Input.GetKeyDown(Keycode))? :)

I suppose I could do that if I'm desperate, but I'm concerned about edge cases and side effects.  For example:

  • suppose the control input's coming from another controller, such as a joystick?
  • what if some other control is capturing the input, so that it's not actually going to the spacecraft input pipeline?

Basically, there's a thing I want to do, and if there's a reasonably straightforward way to do it that addresses the "root cause" of what I want to trap, I'll do it.  But if it turns out to be a series of Rube Goldberg contortions that involve hacking something and then applying patches on patches on patches to deal with edge cases, then I'd just as soon not-- it's not a feature worth spending weeks on.

I'm hoping there's some vaguely sane answer in the API.

Thank you, though!

Link to comment
Share on other sites

Well, I thought my idea would be a bit rough but sometimes, a mediocre idea will lead to a better solution just by pointing out a different way so I shared it ;)

I actually found something in the API which may fit's your requirements:

Quote
FlightCtrlState FlightInputHandler.state
static

A handle to the input state. WARNING: Don't use this to read input state for part modules and such. Use vessel.ctrlState instead.

this script handles all keyboard input for the flight mode it dispatches a flight control update message for all parts that can respond this message contains a flightcontrolstate object, that holds the state of the input much like a snapshot of the cockpit controls

https://kerbalspaceprogram.com/api/class_flight_input_handler.html#ab309a576ff6585b88866641ea108b86b

Link to comment
Share on other sites

As it happens, I was able to find a compromise that works well enough for my specific use case.

Instead of checking whether pitch/yaw/roll are zero, I just check whether they have an absolute value below a fairly low threshold, like 0.1 or 0.15.

That way, it triggers for heavy control inputs such as the keyboard, or SAS if it's heavily torquing (which I'm fine with for this case), but doesn't trigger on the small fluctuations that SAS induces on an "idle" ship.

Link to comment
Share on other sites

20 hours ago, EchoLima said:

In the PAW for command modules and probes, you can select between "SAS Mode" and "pilot mode" (if I'm remembering correctly). I'm no programmer, but maybe there's a boolean that you can use?

Also, this API might be helpful.

Thank you, but that's not actually what I was looking for. I'm not trying to detect whether or not SAS is turned on, or what mode it is in.

Rather, I'd want to detect is whether the player's hands are currently touching the controls, regardless of whether SAS is turned on or off.

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