Hi there, can any1 tell me how i setup configurable joint which i can control by W.A.S.D. keys?
i cant simply use the fpswalker for example. as the anchor is placed out its center.
TIA! :)
Hi there, can any1 tell me how i setup configurable joint which i can control by W.A.S.D. keys?
i cant simply use the fpswalker for example. as the anchor is placed out its center.
TIA! :)
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:
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)
Duck,
Did you use configurable joints for the "hydraulic" components of the arms as well? If so, did you find a quick way to calculate the target angles for the piston and cylinder? I've been beating my head on this one.... Tried colliders as well. Anything you can offer in regards to the hydraulic motions would be very helpful.
I like your excavator demo - it's that time of year again!