x


Directly Rotate a Hinge?

Hey guys, I've got most of this game worked out, and it's actually functioning great, but I'm trying to add another control scheme and I can't seem to get it working... In the game, you're arms are attached to the body via hinge joint, and you press Left/Right to rotate them around using this type of action:

if(Input.GetKey("d")){

    hingeJoint.motor.force = force;
    hingeJoint.motor.targetVelocity = 350;
    hingeJoint.motor.freeSpin = false;

}

Now, I also set this up for use with my PS3 controller, as such:

    if(Input.GetAxis("LHorz")){
    hingeJoint.motor.force = force;
    hingeJoint.motor.targetVelocity = velo*rotspeed;
    hingeJoint.motor.freeSpin = false;

}

What I want to be able to do, is instead of just adding to the motor's velocity, I want to be able to rotate the arm to point exactly where the analog stick is pointing. The code that I can use that works fine for a regular object is this:

var axisHorizontal = Input.GetAxis("Horizontal");
var axisVertical = Input.GetAxis("Vertical");

transform.localRotation = Quaternion.Euler((Mathf.Atan2(axisHorizontal, axisVertical) * Mathf.Rad2Deg), 0.0 , 0.0);

The problem is, is when you apply that code to the arms, which again are attached to the body by a hinge joint, the whole character just goes absolutely haywire...

Here's a pic so you can get the idea of what motion I'm trying to get at:

alt text

Thanks so much for any help!

more ▼

asked Feb 07 '12 at 04:35 AM

kewlhead gravatar image

kewlhead
16 6 8 8

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
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:

x2249
x223
x154
x41
x38

asked: Feb 07 '12 at 04:35 AM

Seen: 545 times

Last Updated: Feb 07 '12 at 04:35 AM