Well, this answer would depend on what particular part of the configurable joint do you want to control? There are a lot of different settings, and you could control many of them via keyboard input.
First off, the WSAD keys (and the arrow keys) are mapped to the "Vertical" axis and "Horizontal" axis by default, so unless you've changed the input settings, you can grab these values as a range from -1 to 1 by using Input.GetAxis, like this:
Input.GetAxis("Vertical")
// and...
Input.GetAxis("Horizontal")
Then, for instance, if you wanted to control the targetRotation value of your configurable joint, you could use something like the script below in your Update() function. 'rotateSpeed' would be a float variable that determines the speed at which the target angle changes (in degrees per second), and "thisConfJoint" would be a reference to the joint being controlled. The script rotates the targetAngle of the joint around its x axis.
void Update()
{
targetAngle += Input.GetAxis("Horizontal") * Time.deltaTime * rotateSpeed;
Quaternion targetRotation = Quaternion.AngleAxis( targetAngle, Vector3.right );
thisConfJoint.targetRotation = targetRotation;
}
Of course, adjusting the configurableJoint's target rotation will only have an effect if you've set up the joint's other settings correctly so that the joint automatically applies a torque force to actually reach the specified target rotation. By default, all these settings are off so it won't do anything.
To have a joint apply torque to move towards its targetAngle (in our case, just the X axis is used) you need to set up the joint properly. For this particular example, these are the settings you'd need:
- XMotion : Locked
- YMotion : Locked
- ZMotion : Locked
- Angular XMotion : Limited
- Angular YMotion : Locked
- Angular ZMotion : Locked
- Rotation Drive Mode : X & YZ
- Angular XDrive:
- Mode : Position
- Position Spring : 1000
- Position Damper : 200
- Maximum Force : 10
You will no doubt want to configure your own spring, damper and max force values to suit the mass of the objects in your scene.
I used a system very similar to the above described method to the Excavator Arm Controls in this Christmas Demo! (You can smash up ice sculptures with an excavator)
Skive Christmas Excavator Demo
(the link to play is at the bottom of the blog post)