Jump to content

Reading control inputs


Recommended Posts

How would I make a plugin read the player's control inputs (aileron, elevator and rudder)? Also, how can I pass that information to the craft's control surfaces without having the default controls getting in the way? (Read: How do I override the default controls with a plugin and control the spacecraft through said plugin?)

I'm trying to write a plugin that takes the player's input, then does some fancy stuff with it and eventually passes the values to the spacecraft.

Link to comment
Share on other sites

Use of the fly by wire system is detailed here: http://wiki.kerbalspaceprogram.com/wiki/Module_code_examples#Fly-by-wire

For reading the controls you'd normally use:

vessel.ctrlState.* (pitch, roll, yaw)

as that accounts for fly by wire, trim etc.

But if you're after the player input directly then I'm not sure where that is. You can probably check for it yourself though, the keycodes are in GameSettings and the Input commands are detailed here: http://docs.unity3d.com/Documentation/ScriptReference/Input.html

Link to comment
Share on other sites

Well, here's the code I've got at the moment:

http://pastebin.com/j07cXEfv

That works. It prints the pitch control value in the debug console. What I'm trying to do now (as you can probably see) is dividing the input by 2 and then sending it out to the control surfaces. For example, pulling the stick fully back should only give 50% deflection on the elevators. Is there a way to do that? I'd imagine there is since Ferram's Aerospace Research mod has these dynamically adjusting control surfaces that move the less the faster you fly. I had a look at his source code but couldn't figure it out.

Link to comment
Share on other sites

As far as I know FAR re-implements control surfaces from scratch, so his code isn't going to be much use.

It depends on the order of executation and how many FlightControlState objects there are as to whether you can get away with code like that. Try s.pitch = FlightInputHandler.state.pitch / 2

You may also need to move the callback to OnStart as I didn't think vessel exists when OnAwake is called.

Otherwise you'll have to monitor the input keys.

Edited by EndlessWaves
Link to comment
Share on other sites

Thanks! I got the breakthrough I've been looking for. I tried the s.pitch = FlightInputHandler.state.pitch / 2 one to tell the game directly what to do. It worked. Then I moved the FlightInputHandler.state.pitch / 2 part to the OnFixedUpdate method, told it to store the value in a variable, then had the FlightCtrlState class take the value from that variable, divide it by 2 and then send it to the actual controls. It worked as well! Time to code a simple speed-sensitive pitch control just to be sure it works.

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