x


Keyboard controlled knee. (QWOP mechanic)

Hiya guys. I am tring to create a human body with fully controllable joints. In the end it probably would look something like this: QWOP (I am also working in 2d)

I am using configurable joint with these settings:

  • XMotion : Locked
  • YMotion : Locked
  • ZMotion : Locked
  • Angular XMotion : Limited
  • Angular YMotion : Locked
  • Angular ZMotion : Locked Low angular XLimit : Limit -70 High angular XLimit : Limit 70
  • Rotation Drive Mode : X & YZ
  • Angular XDrive: Mode : Position
  • Position Spring : 1000
  • Position Damper : 200
  • Maximum Force : 10

The script to control the movement is this:

    void Update()
{
    targetAngle += Input.GetAxis("Vertical") * Time.deltaTime * rotateSpeed;
    Quaternion targetRotation = Quaternion.AngleAxis( targetAngle, Vector3.right );
    thisConfJoint.targetRotation = targetRotation;
}

So THE PROBLEM is basically this - it doesn`t work the way I want to. The value of "targetAngle" can go higher or lower than the angle the leg can bend, and that causes the legs to jump around (if I hold down long enough for targetAngle go from +70 to -70 the wrong way) or a lag between movements (when targetAngle crosses the 70* line, and I have to wait for it to move back).

I am pretty new both to Unity and programming, and cant seem to find a way to limit targetAngles value in the boundaries, or think of alternative solution for this. This is where I come to you guys - could anyone at least hint me the right direction to look at? :)

more ▼

asked Jan 02 '12 at 03:02 PM

wolis gravatar image

wolis
26 5 8 9

I also tried to use transform.rotate on different limbs with character joints, but it doesn`t seem to work either :/

Jan 03 '12 at 08:50 AM wolis

Is this question too hard or not clear enough? :/

Jan 03 '12 at 01:27 PM wolis
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Fixed it with this line targetAngle = Mathf.Clamp( targetAngle, -70, 70);

more ▼

answered Jan 04 '12 at 09:28 AM

wolis gravatar image

wolis
26 5 8 9

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2244
x1071
x154
x137

asked: Jan 02 '12 at 03:02 PM

Seen: 671 times

Last Updated: Jan 04 '12 at 09:28 AM